Prompt & Context Engineering
Every AI engineer interview touches this topic because it is the highest-leverage, lowest-cost knob you control in production: most quality problems are context problems, not model problems. Expect it in product-engineering loops ("design the prompt for this feature"), agent-design rounds, and debugging exercises ("this prompt regressed - why?").
Card 1 of 13
Roles: the prompt is an API surface
System = who the model is and the rules of engagement: persona, capabilities, output contract, safety constraints, tool usage policy. User = the task and the data for this turn. Assistant = model output, and a steering surface: prior assistant turns in few-shot dialogues teach by demonstration. Some APIs have also let you prefill the assistant turn (start it with { to force JSON), but support is shrinking - Anthropic's Claude 4.6 models reject a trailing assistant message outright - so treat prefill as a legacy trick and use native structured outputs for format control. Instructions in the system prompt are weighted more heavily by instruction-tuned models and survive multi-turn drift better than instructions buried in a user turn. Don't put per-request data in the system prompt (it kills caching) and don't put standing policy in user turns (it gets ignored after a few turns).
All 68 Prompt & Context Engineering questions
Basic
- What's the difference between zero-shot and few-shot prompting, and when would you use each?
- Explain the system, user, and assistant roles. What belongs in each?
- What is chain-of-thought prompting? When does it help, and when is it unnecessary or harmful?
- What is zero-shot CoT - and why did "Let's think step by step" become famous?
- What are the most common prompt anti-patterns you'd flag in a code review?
- What is "context engineering," and how is it different from prompt engineering?
- When would you ask for JSON, XML tags, or markdown as your output format?
- What do temperature and top_p actually do, and how do you choose them per task?
- How do you build a prompt template, and what can go wrong when you inject variables into it?
- Should you treat your system prompt as a secret? What happens when it leaks?
- What is the difference between input guardrails and output guardrails, and why do you need both?
- Your chatbot starts losing the thread after about ten turns. What are your options for managing conversation history?
- Your model's answers are consistently too long. How do you control output length reliably?
Intermediate
- How do you select and order few-shot examples? What are the known pitfalls?
- Why does in-context learning work at all? The model's weights don't change.
- Explain self-consistency. When is it worth the cost?
- When would you decompose a task into multiple prompts instead of one? Explain least-to-most prompting.
- Describe the ReAct pattern. How does it relate to modern native tool calling?
- How do you design good tool/function definitions for an LLM? What makes tool calling fail?
- How do you structure a prompt to be resistant to prompt injection from retrieved or user-supplied content?
- You have a 200k-token context with instructions and 50 documents. Where do you put what, and why?
- How does prompt caching work, and how should it change the way you structure prompts?
- Walk me through your process for systematically improving a prompt that's underperforming.
- What changes when your product must handle prompts and content in multiple languages?
- How do you version and govern prompts in production? Someone asks which prompt produced a bad output three weeks ago - can you answer?
- You want to switch model providers and your prompts break. Why, and how would you have made them portable?
- Design an example store for dynamic few-shot selection. What do you get, and what does it cost you?
- How should tool results be formatted before they go back into the model's context?
- When is prompt compression worth it, and how would you do it?
- You have retrieved chunks and a question. How do you actually build the prompt? Assume some documents are irrelevant and two of them contradict each other.
- Your model refuses requests that are perfectly legitimate. How do you diagnose and fix over-refusal?
- A user reports a bad answer. Walk me through how you debug it.
- How is a system prompt for a long-running agent different from one for a single-shot feature?
- The model does not know what day it is. How do you handle dates, recency and the knowledge cutoff in your prompts?
- What belongs in a repository instruction file such as AGENTS.md or CLAUDE.md for a coding agent, and what should stay out?
- Cache writes now cost extra on most major providers. How do you decide whether a prefix is worth caching, which TTL to pay for, and when to use explicit breakpoints instead of automatic caching?
Advanced
- Compare JSON mode with schema-constrained decoding. How does constrained decoding actually enforce the schema?
- What is context rot, and what compaction strategies do you use in long-running agents?
- Explain DSPy-style programmatic prompt optimization. When would you use it over manual iteration?
- What is meta-prompting? How would you use a model to improve your prompts - and what are the pitfalls?
- How do you decide when to stop prompt engineering and fine-tune instead?
- How would you A/B test a prompt change safely in production?
- How do reasoning models change prompting practice? What transfers and what becomes obsolete?
- Design a token budget for an agent with a 200k context window. How do you allocate it, and how do you enforce it?
- Design memory that persists across sessions for an assistant. How is it different from managing context within a session?
- Your agent reads web pages and can send email. How do you defend against indirect prompt injection?
- The system prompt says one thing, the user asks for another, and a retrieved document says a third. How do you design conflict resolution?
- Your prompt change gained 3 points on the eval. How confident are you that it is real?
- When should you split an agent into sub-agents, and what do you pass between them?
- You moved a prompt from a hosted API to a self-hosted copy of the same open-weight model, and quality dropped below the hosted version. What do you check?
- You are running a reasoning model in a multi-turn tool-use loop. What do you do with its reasoning between calls, and what breaks if you drop it?
- Reasoning effort can now be changed per message, mid-conversation, without losing the prompt cache. Design an agent policy that raises and lowers effort turn by turn, and explain the effect on cost, latency and cache hit rate.
- You make 50 million yes/no and routing decisions a day with an LLM. Would you use a decision endpoint that returns probabilities, structured output with a label, or logprobs you read yourself? How do you set and maintain the thresholds?
Quick-fire
- What is context engineering, and why can it matter more than prompt wording?
- Walk through the main prompting techniques and when to use each.
- How do you get reliable structured output (for example JSON) from an LLM?
- What is "lost in the middle" and how do you design around it?
- How do you debug a prompt that works most of the time but fails intermittently?
- What is few-shot prompting's cost, and when should you avoid it?
- How do you manage conversation history in a long chat without blowing the context budget?
- What is context rot, and how does it change how you build long-running agents?
- What is context compaction, and when do you reach for it?
- What is the difference between system, developer, and user roles, and why does it matter for injection safety?
- Why structure a prompt with delimiters or tags, and how does it help reliability?
- How do you treat prompts as versioned, testable artifacts rather than strings in code?
- What is prompt sensitivity, and how do you make a prompt robust to it?
- When should you decompose a task into multiple prompts instead of one big prompt?
- What is meta-prompting or using a model to improve your prompts?