Prompting & structured output
System prompts, few-shot examples, JSON-mode/tool-calling for reliable outputs, and prompt versioning. Treat prompts as code with tests.
The mental model
A prompt is an API contract with a probabilistic function. You are not "talking to" the model — you are configuring a stochastic text-completion engine whose output distribution you can only shape, never fully pin down. The analogy that sticks: briefing a brilliant contractor who has total amnesia between jobs. Every single request, you re-explain who they are (system prompt), show them two or three finished examples of what "done" looks like (few-shot), hand them the raw materials (context), and — critically — give them a form to fill in rather than a blank page (structured output). A contractor with a form produces the same shape of deliverable every time; a contractor with a blank page produces whatever felt right that morning.
Why this discipline exists: the moment an LLM's output feeds another program instead of a human's eyes, free-form text becomes a parsing time bomb. A model that answers Sure! Here's the JSON you asked for: before the JSON breaks json.loads on some fraction of requests, and that fraction changes every time you touch the prompt or the provider bumps the model. Teams that treat prompts as chat messages ship demos; teams that treat prompts as versioned, tested code with schema-enforced outputs ship products. Without prompt versioning you cannot answer "which prompt produced this bad output last Tuesday", and without structured output you are regex-parsing a moving target.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision