DEV Community

Hafiz Syed Ashir Hassan for AWS Community Builders

Posted on • Originally published at community.aws

Prompt Engineering with Generative AI

See any GenAI model as a genius boy who is dump to answer. He has all the knowledge but don't know what and how to answer. The tool to fetch your answer in most accurate and well structured way is called Prompt Engineering.

Here I will mention 3 techniques for well prompt engineering.

Clear Prompting:
We have a lot in our head which we don't say because it is 'common sense.' As a wise man said: "common sense is not common", thus we need to be clear, direct, well structured and well explained while giving prompts.
The below example shows that when we ask a question, it may get confuse or give details that is more needed. But when we are direct, it give is a better answer.

Indirect Prompt:

Image description

Direct Prompt:

Image description

Ask to think Step-By-Step:
This method, also referred to as chain of thought (CoT) prompting, can greatly enhance the accuracy and depth of a model.

Image description

Now ask to think step by step:

Image description

Reduce Hallucination:
To reduce hallucination, can follow the steps:

  1. Ask the model to answer only if it is confident and sure about the response.
  2. Give the model space to think before responding by encouraging step-by-step reasoning.
  3. Ask the model so say "I don't know the answer" if it is not sure or don't have the answer.

Top comments (0)