In this post
What goes into context
- Instructions and role.
- The user’s request and recent conversation.
- Retrieved documents and tool results.
- Examples of the desired output.
- Constraints and output format.
Principles
- Be specific. State the task, the audience and the format.
- Show, don’t just tell. A few good examples beat a long description.
- Keep it relevant. More context is not better context; irrelevant text can mislead the model.
- Order matters. Put the most important instructions where the model will weigh them.
- Version it. Prompts are code: review, test and track them.
Test the prompt like software
Keep a set of inputs with expected qualities, run every prompt change against it, and look at regressions as well as improvements.
Treat outside text as untrusted
Documents and web pages can contain instructions aimed at the model. Separate trusted instructions from untrusted content, and never let retrieved text widen what the system is allowed to do.
Sources and further reading
- Anthropic. Prompt engineering overview. docs.anthropic.com.
IICTP is a new independent credential and is not ISO/IEC 17024 accredited.