Interview Study Guide

Guide / AI engineering Fundamentals

15. Prompting, structured output, context engineering

Created · Updated · 2 min read

15.1 Prompt techniques#

  • Clear system prompt: role, task, constraints, output format, what to do when unsure. Specific beats clever.
  • Few-shot examples: 2–5 diverse input/output examples; include edge cases and a “refuse/unknown” example.
  • Chain-of-thought / reasoning: ask the model to reason before answering for multi-step problems (or use a reasoning model); hide the reasoning from end users if needed.
  • Decomposition / prompt chaining: split a big task into steps (extract → validate → generate), each simpler and testable. Usually more reliable than one mega-prompt.
  • Delimiters and tags: wrap documents and user input in clear tags so the model separates instructions from data (also a prompt-injection mitigation).
  • Self-consistency: sample several answers and take the majority, for high-stakes reasoning.

15.2 Structured output#

  • Use the provider’s JSON mode / structured outputs / tool-call schema (constrained decoding guarantees valid JSON matching the schema) rather than asking politely for JSON.
  • Validate anyway (Zod, Pydantic, JSON Schema): types, enums, ranges, business rules. On failure: retry with the validation error in the prompt (1–2 times), then fall back.
  • Keep schemas small and flat; give fields descriptive names and descriptions; use enums for categories.

15.3 Context engineering#

The term for deciding what goes into the context window for each call — now considered the core applied-AI skill.

  • Budget the window: system prompt + tools + retrieved docs + conversation history + output. More context is not better: irrelevant text lowers accuracy and raises cost.
  • Order: stable instructions and reference material first (cacheable), the question last.
  • History management: keep recent turns verbatim, summarize older ones, drop tool outputs once used, or store facts in long-term memory and retrieve on demand.
  • Tool definitions consume tokens: 50 tools in context confuse the model — select tools dynamically per step.
  • Just-in-time retrieval: let the agent fetch details when needed (search, file read) instead of stuffing everything upfront.

15.4 Prompt management in production#

  • Prompts are code: store them in Git with versions, review changes, roll back (you built Git-backed rollback — talk about it).
  • Every prompt change runs the eval suite before rollout; canary new prompts to a % of traffic.
  • Template variables, not string concatenation; log the rendered prompt version with each trace.
  • Pin model versions; a model upgrade is a change that needs evals like any other.
Finished this page?Mark it done to track your progress across the guide.
Pritam Ghosh · System design & AI engineering study notes