Skip to content

Prompt Engineering

Last reviewed: September 2026

Prompt engineering addresses “how to question/instruct a model to get the desired output.” The same model produces vastly different quality depending on the prompt.

Per Anthropic’s official guide, prompt engineering is an “empirical science” — the most important thing is defining evaluation criteria → iterative testing. It’s not about finding a “good prompt” but improving through measurable metrics — Anthropic Prompt Engineering Guide

Common principles emphasized by Microsoft, Google, and Anthropic guides:

  • Clear, specific instructions — Vague requests produce vague answers.
  • Provide context — Give background information the model doesn’t have.
  • Assign a role — Persona setting like “You are a legal expert.”
  • Specify output format — JSON, list, paragraph, etc.
  • Provide examples — Input/output examples improve quality (Few-shot).
  • Iterate with evaluation — Measure quality on representative cases, then refine.

Sources:

Direct instruction without examples. Suitable for simple tasks but quality drops on complex ones.

Analyze the sentiment of the following sentence: "Today's meeting was boring."

Show desired patterns via examples first. The LLM mimics the format.

Classify each sentence as positive/neutral/negative.
Sentence: "The service was excellent."
Answer: Positive
Sentence: "Delivery arrived on schedule."
Answer: Neutral
Sentence: "The product arrived damaged."
Answer:

Sources:

Guide the model to reason step by step. Dramatically improves accuracy on math, logic, and complex classification.

Solve this step by step.
Problem: A store has 23 apples. 20 were sold. Then 6 new ones arrived. How many are there now?
Steps:
1.

Latest frontier models (Claude, GPT, Gemini families, etc.) sometimes perform CoT internally, but explicit “Think step by step” instructions remain effective.

Sources:

Assign a role to shape tone, expertise, and response scope. Most APIs support a separate system prompt.

You are a Korean legal expert. Explain in terms a layperson can understand,
while using legal terminology accurately.
Question: What do the contract terms '갑' (gap, "Party A") and '을' (eul, "Party B") mean?

See the Anthropic guide for more on system prompts.

Specify desired format (JSON, XML) explicitly.

Extract information from the review below as JSON.
Schema:
{
"product": "product name",
"rating": "integer 1-5",
"sentiment": "positive" | "neutral" | "negative"
}
Review: "These earbuds are amazing! Great sound quality and long battery life. Five stars."

Some vendors natively support Structured Outputs:

The LLM alternates “think → tool call → observe → next thought” in a loop. Foundational pattern for agent implementations.

Available tools:
- search(query): web search
- calculate(expression): calculation
Question: What is the distance between the 2024 Olympics host city and Seoul?
Thought: First, I need to find the 2024 Olympics host city.
Action: search("2024 Olympics host city")
Observation: Paris
Thought: I need to calculate the distance between Paris and Seoul.
Action: search("distance Paris Seoul")
Observation: approximately 8,957 km
Answer: The 2024 Olympics host city is Paris, approximately 8,957 km from Seoul.

Sources:

Knowing the patterns matters less than judging which technique to use when. Consider the situation, model characteristics, and cost together.

Situation Recommended technique Why / caution
Simple classification/extraction/transformation Zero-shot Sufficient without examples; minimizes token waste
Tricky output format or tone Few-shot “Show” the format with 2–5 examples; avoid biased examples
Multi-step reasoning, math, logic Chain-of-Thought Elicits intermediate reasoning. But reasoning-specialized models (o-series, reasoning modes) build in CoT, so explicit CoT is unnecessary or even counterproductive
Structured output (JSON, etc.) required Output-format enforcement + schema Native structured-output / function-calling APIs (where supported) are more reliable than prompt instructions
Combined with external tools/search ReAct / tool calling Agentic workflow; needs loop-cost and infinite-loop safeguards
Consistent role/policy System Prompt / Persona Fixed across the session; must not be overridden by user input

By model type:

  • General models (GPT-6, Claude Sonnet, etc.): Few-shot and CoT meaningfully improve quality.
  • Reasoning-specialized models (o-series, Claude reasoning mode, etc.): They reason internally, so “think step by step” instructions are unnecessary, and excessive CoT can hurt performance and cost.
  • Cost angle: Few-shot examples and CoT increase input tokens. On high-frequency paths, minimize example count / reasoning length or use prompt caching.
Vendor Key Recommendation Reference
AWS Bedrock (Claude) Structure with XML tags (<context>...</context>), clear instructions first Claude best practices
Microsoft Foundry (GPT) Fix role via system prompt, provide format examples Azure prompt engineering guide
Google Cloud (Gemini) Clear instructions, explicit constraints, iterative experimentation Vertex AI Prompt strategies
OCI (Cohere) Preamble for persona, precise JSON schema for tool use Cohere Prompt Engineering
graph LR
    A[1. Define Success Criteria] --> B[2. Build Eval Set]
    B --> C[3. Draft Prompt]
    C --> D[4. Run Evaluation]
    D --> E{Meets Criteria?}
    E -->|No| F[5. Refine Prompt]
    F --> D
    E -->|Yes| G[Deploy]

A “good prompt” is never completed in one shot. Build an eval set of 20–50 representative questions and compare evaluation scores on each prompt change.

  • Too many instructions in one prompt — 5+ directives are easily missed by models.
  • Demanding complex formats without examples — Few-shot examples are far more effective.
  • Testing only representative questions — Quality can collapse on edge cases.
  • Not re-evaluating prompts on model upgrades — Same prompt may produce different output across model versions.