Advanced prompting techniques
Few-shot examples, step-by-step reasoning, prompt chaining, self-critique, structured outputs and evaluation: techniques for more reliable results.
Once you master the basics, these techniques help you get more reliable, consistent results, especially for complex or repetitive tasks.
Few-shot: learning from examples
Include 2-5 input/output examples before the real task. It is very effective for classifying, extracting information or imitating a format:
Classify the sentiment of each review as positive, negative or mixed.
Review: "Arrived fast, but the size runs small." → mixed
Review: "Perfect, will buy again." → positive
Review: "Broken from day one." → negative
Review: "Lovely color, although it took two weeks." →
Use varied examples so the model does not copy irrelevant details.
Step-by-step reasoning
For logic, math or analysis problems, ask it to reason before concluding: “analyze the problem step by step and then give the final answer in one line”. Many current models already reason internally, but asking for an explicit structure helps you review the process.
Prompt chaining
Split a large job into stages, using one stage's output as the next stage's input:
- Extract key points from 20 interviews.
- Group the points into themes.
- Prioritize themes by frequency and impact.
- Write the report.
Each stage is easier to review and correct.
Self-critique and review
Ask the AI to review its own work against specific criteria:
Review your previous answer against these criteria: accuracy, clarity
for a beginner and whether it answers every question. List the problems
and then write an improved version.
Structured outputs
To integrate AI into apps or automations, ask for a strict format (e.g. JSON with specific keys) and include an example of the schema. Some APIs offer structured output modes that guarantee the format.
Multiple perspectives
Ask it to analyze a problem from several viewpoints, or to produce the strongest argument for and against before recommending.
Evaluate your prompts
If a prompt will be used many times (for example, in an agent or automation), build a set of test cases with the expected answer and check every new version of the prompt against all of them. The library has a prompt to design an AI agent's system prompt that includes test cases.
Security
If your prompt processes third-party text (emails, web pages, documents), delimit it clearly and tell the AI to treat that content as data, not instructions. This reduces the risk of prompt injection.