Skip to main content
Best practices for prompt engineering apply to both the system message and the prompts you send to the AI agents. 1. Put instructions at the beginning of the prompt and use markdown headers or code blocks to separate the instruction and context Less effective ❌:
Better ✅:


2. Be specific, descriptive and as detailed as possible about the desired context, outcome, length, format, style etc Less effective ❌:
Better ✅:


3. Articulate the desired output format through examples Less effective ❌:
Better ✅:


4. Try using zero-shot and few-shot examples Use zero-shot for simple tasks and few-shot for more complex ones. If neither work, consider fine-tuning the model. Example of Zero-shot:
Example of Few-shot:


5. Reduce “fluffy” and imprecise descriptions. Be clear and succinct in your instructions. Less effective ❌:
Better ✅:


6. Instead of just saying what not to do, say what to do instead Avoid negative instructions, and provide clear guidance on what actions should be taken. Less effective ❌:
Better ✅:


7. Code Generation Specific - Use “leading words” to nudge the model toward a particular pattern Less effective ❌:
In this code example below, adding “import” hints to the model that it should start writing in Python. (Similarly “SELECT” is a good hint for the start of a SQL statement.) Better ✅:

Resources

OpenAI, Best practices for prompt engineering with OpenAI API Prompt Hub, 10 Best Practices for Prompt Engineering with Any Model