Overcome AI Hallucinations: Netguru’s Guide to Prompting

Photo of Patryk Szczygło

Patryk Szczygło

Nov 15, 2024 • 13 min read
Two  colleages discussing ideas using a tablet and computer-4

Prompt engineering is quickly becoming one of the most important — and well-paid — skills. And it’s easy to see why.

AI tools promise to boost creativity and supercharge productivity. But unlocking those benefits depends entirely on how well you prompt them.

According to the 2024 Global AI Workplace Report, 72% of employees believe that AI can add value to everyday work. That said, those who heavily criticize AI for its generic or inaccurate responses usually don’t know how to prompt these systems correctly. They end up frustrated with the technology. If that sounds familiar, it doesn’t have to be you!

Prompt methods to choose from

Here are some tried-and-tested prompt methods and other tips you can use to get great results and overcome AI hallucinations — every time.

1. Role prompting

The first prompt method I’m going to cover is one of the most important.

Role prompting is when you ask the AI to respond to you as if it were a specific person, profession, or character. The reason for doing this is to guide the AI to give more focused, creative, or empathetic answers.

Here's how it works:

  1. Start by choosing a relevant role — like a profession — that fits your question.
  2. Set the scene to help the AI understand the point of view.
  3. Finally, ask your question or set a task with that role in mind.

For example, if you want ideas on how to tackle deforestation, you might say:

“As a climate scientist, how would you reduce the environmental impact of deforestation?”

The most important part is “As a climate scientist, …”. It sets all the internal parts of the AI to focus on this area of its data. Models are relying on the probability of certain words – using techniques like role prompting, we can get more accurate and personalized responses.

With such a prompt, AI is more focused on ‘thinking’ like a climate scientist rather than picking up generic ideas.

Role prompting works well on its own, but you can make it even more effective by combining it with other methods — like the ones I'm about to cover.

2. Few shot prompting

Few shot prompting is a technique where you provide the AI with a few examples of the response style or task you’re looking for. These examples, or 'shots', help the AI understand your expectations before it tackles your main question or input. It's especially helpful for guiding the AI on complex tasks.

Here’s how to use few shot prompting:

  1. Choose a few examples — between two or five— that demonstrate what you’re looking for.
  2. AI can understand a pattern. Ensure that your pattern is clear.
  3. Balance the number of examples. Too few examples may not be clear, but too many can create repetition.
  4. At the end, establish the pattern. It should look like a template in which you can fill in the gaps.

For instance, if you want the AI to perform sentiment analysis, you could set up a few examples like this:

“The movie was fantastic” – Positive

“I didn’t enjoy the food at all” – Negative

“Amazing vacation, I had a great time” – Positive

“She looks upset and angry” – Negative

After providing these examples, you can add the new sentence you want the AI to analyze. For instance:

“The book was hard to put down” - {sentiment_label}

Because of the pattern you’ve established, the AI should respond with 'Positive'.

Few shot prompting is great because it’s flexible and can be adapted to many tasks. But you may need to experiment with different examples to find the right balance.

3. Chain of thought

For a really powerful prompt, combine either of the methods above with ‘chain of thought’. The newest gpt-o1 from OpenAI is using this technique under the hood. AI is ‘thinking’ and by doing that, it builds up all the probabilities of the next words. Remember role prompting? This is a more advanced take on a similar concept.

Chain of thought method guides the AI to think step-by-step, helping it break down complex ideas into smaller parts. Instead of answering a big question all at once, a chain of thought prompts the AI to explore each part in order, leading to a clearer, more thoughtful response.

Here’s how to use it:

  1. Start with a focused question to introduce the topic.
  2. Add follow-up questions that go deeper into each point.
  3. Guide the AI step-by-step so its response stays organized.

For example, if you want insights on remote work, you might prompt:

  • “List three reasons why people might prefer working from home.”
  • “For each reason, explain how it benefits individuals or organizations.”
  • “Now, list three challenges of working from home and suggest ways to solve them.”

4. Zeroshot chain of thought

Easier – and less reliable – idea is to let AI do the job. Such an approach is ideal when we don’t have enough knowledge on the topic and we want to explore something new. We prompt the AI to explain its thinking step-by-step without providing examples first. It’s particularly useful for questions that require logical reasoning or involve multiple ideas.

In simple terms, here’s how it works:

  1. Define a clear question to get the AI started.
  2. Ask for step-by-step reasoning so the AI logically connects each idea in its answer.

For instance, if you want to explain how a solar panel works, you could prompt:

“Explain how a solar panel works, starting with sunlight hitting the panel’s surface and ending with electricity being produced. Structure your response step-by-step.”

By guiding the AI to walk through its thought process, you can get more logical, insightful answers. The technique can boost accuracy and usefulness of the answer by as much as 10%.

5. Dual prompt approach

The final prompt method I'm going to talk about is the ‘dual prompt approach’, where you use two or more prompts to guide the AI in generating more specific and meaningful responses.

It helps overcome AI hallucinations by refining broad prompts and getting the detailed information you need.

Here’s how it works:

  1. Start with a broad prompt to outline the general task.
  2. Follow up with a second prompt that narrows the focus or asks for more detail.

Refining a text? It’s a great example of a dual prompt approach use case. Let’s say you have ready to use articles, but you’d like to optimize your content for SEO, or maybe simplify your language for a particular audience. You can prompt:

“List the most important SEO principles for blog articles.”

Then follow up with your text after an additional prompt:

“Based on the list improve the following text: <put your text here>”

This dual prompt lets you pick up the best practices from any industry and then apply for the task you have.

How to stop AI from hallucinating

I’ve outlined some of my favorite prompt methods. Now I’ll share some other useful tips to help overcome AI hallucinations.

1. Clear instructions: include details in your query

This might sound obvious, but it's a really important way to stop the AI from producing irrelevant or incorrect information. The more specific you are, the more likely you’ll get accurate answers. Avoid vague or overly broad questions. Instead, include detailed information to guide the AI’s response.

For example, instead of asking:

“Who is the president?”

Ask:

“Who was the president of Mexico in 2021, and how often are elections held?”

This gives the AI the context it needs to deliver a more relevant and reliable answer.

2. Ask the model to adopt a persona

I've already talked about 'role prompting'. Asking the model to adopt a specific persona is a great way to overcome AI hallucinations. By assigning the AI a role — like a politics expert or Excel specialist — you give it a clear perspective from which to answer.

For instance, instead of asking:

“How do I use addition in Excel?”

You might say:

“As an Excel expert, explain how to use formulas to add numbers.”

This ensures the AI answers from a knowledgeable standpoint. And it improves the chances of getting a high-quality response.

3. Use delimiters to clearly distinguish between your questions and sources

Here’s another pro tip to stop the AI from getting confused. Use delimiters like quotation marks, brackets, or dashes to separate your questions from any sources or information you provide.

For example, you could write:

“Summarize the following text between“””.

“””

Your text

“””

This way, the AI focuses on the right parts of the prompt.

You might want to add additional text at the end. Without specified delimiters it will become part of the text to analyze instead of a new instruction. Delimiters really boost the performance of the model.

4. Specify the desired length of the output

When asking AI for a response, I’d advise you to be specific about how long you want the answer to be. If you leave it open-ended, the AI might follow common patterns from its training data, which could lead to longer or shorter outputs than you intended.

For example, if you need exactly three bullet points, say so. By clearly specifying the length, you can ensure the AI provides the right amount of detail.

5. Ask the AI to use direct quotes from your sources

Another way to get more accurate and reliable responses is to tell the AI to directly quote from your reference material.

This helps avoid the common issue of AI paraphrasing quotes, leaving out important details, or worse still, making things up.

To help the AI focus on the right content, include the reference text inside triple quotation marks. You can also ask it to cite specific sections or paragraphs.

6. Have the AI double-check for missing information

Here’s another thing I like to do to make sure the AI’s responses are on point.

If I’m not completely happy with an answer, I’ll ask the AI to check if it missed any important details. But there’s a key tip to make this truly effective: avoid vague follow-up questions like “Are you sure?”

These tend to lead to confirmation bias, where the AI simply repeats itself in different words. Instead, get specific. For example, if the AI provides a summary that feels incomplete, you could ask,

“Can you elaborate on the key points from the last paragraph that weren’t fully explained?”

Or:

“What supporting evidence can you find to back up your claims?”

In my experience, this leads to more detailed and thoughtful responses, without needing to rewrite the entire prompt.

7. Ask the model to go step by step

When tackling trickier tasks, it’s often best to ask the AI to work through the problem step by step.

Doing this ensures the AI doesn't trip up over itself. It has the chance to thoroughly process each part of the task, which reduces the chance of it making an error – or a false assumption based on its training data.

I touched on this earlier with ‘chain of thought’, where breaking down a problem into smaller parts leads to clearer and more reliable answers. I gave you some examples, but here's another. Let's say you want to know the area of a triangle.

Instead of asking:

“How do I calculate the area of a triangle?”

You could say:

  • First, identify the formula for calculating the area of a triangle.
  • Next, explain how to apply the formula using specific measurements.
  • Then, solve for the area.

Going step-by-step like this is particularly useful for tasks involving math, logic, or detailed analysis.

Overcome AI hallucinations

Getting poor responses from AI can be frustrating, but with a little effort and thoughtful prompt structuring, you can easily avoid that. By using tried-and-tested methods like role prompting, few shot prompting, and chain of thought, you’ll immediately level up your results. Combining these techniques can unlock truly excellent responses from the AI.

In my experience, the key is to always be as specific as possible. Clear instructions are essential — give the AI plenty of context, tell it how to structure sections, and be clear about the kind of response you need. Whether you’re asking for bullet points, a detailed paragraph, or just a quick answer, being precise will help the AI deliver more accurate, useful output.

With the right prompting techniques, you’ll take control of the conversation and get the AI to work for you, delivering the high-quality results you’re after. Good luck, and happy prompting!

Photo of Patryk Szczygło

More posts by this author

Patryk Szczygło

Patryk is an engineer leading R&D department to develop more knowledge in cutting edge...
Efficient software development  Build faster, deliver more  Start now!

Read more on our Blog

Check out the knowledge base collected and distilled by experienced professionals.

We're Netguru

At Netguru we specialize in designing, building, shipping and scaling beautiful, usable products with blazing-fast efficiency.

Let's talk business