Prompt engineering is the discipline of structuring inputs so LLMs produce reliable outputs. Five patterns cover 80% of production use: zero-shot, few-shot, chain-of-thought, system+user role split, and structured output. Each one has a specific failure mode it addresses.
Zero-shot
Just ask. 'Translate to French: hello world'. Works for tasks where instruction-tuned models already know the format. Lowest cost. Use as baseline.
Few-shot (in-context learning)
Provide 3-5 input/output examples in the prompt. The model pattern-matches to your examples. Crucial when the task format is non-standard or the model's default answer is too verbose/terse.
Chain-of-thought (CoT)
Q: Roger has 5 tennis balls. He buys 2 cans of 3 balls each.
A: Let's think step by step.
1. Roger starts with 5 balls.
2. He buys 2 cans × 3 = 6 balls.
3. Total = 5 + 6 = 11.
Answer: 11System + user split
Use the system role for invariant instructions (persona, output format, safety rules). Use the user role for the actual query. This separation lets you cache the system prompt and only resubmit user queries — saves ~50% on tokens for chatty apps.
Structured output
Force JSON, XML, or function-call format. Modern APIs support JSON schema enforcement (OpenAI structured outputs, Anthropic tool use). Eliminates parsing failures — the model literally cannot emit invalid JSON when this mode is on.