Skip to content

Chapter 3 of 6

Prompts and Output

Structured output asks the model to return data in a predictable format such as JSON, making it easier to validate and consume by downstream software. To make this reliable in practice, applications use an output parser, a component that validates and converts model text into structured application data. A common mistake is assuming the model will always return perfectly formatted JSON, so parsers must be defensive against malformed responses.

Prompts are the most frequently edited part of an LLM application, which makes prompt versioning essential. Prompt versioning tracks changes to prompts the same way code changes are tracked, and it matters because it makes regressions easier to debug and improvements easier to reproduce. A common mistake is editing prompts in production without a history of what changed, which turns improvements into mysteries when behavior shifts. Before applying a change, asking what problem the new prompt solves, what trade-off it introduces, and how the team will know it worked helps avoid silent regressions.

A related optimization is prompt caching, which reuses repeated context or instructions to reduce cost and latency. It helps apps with large stable context blocks, but a common mistake is caching dynamic or user-specific data incorrectly, which can leak information between users or return stale results. Caching only works when the reused portion is genuinely identical across requests, so designers must separate stable instructions from per-request data carefully.

All chapters
  1. 1Foundations of LLM Applications
  2. 2Retrieval and Knowledge
  3. 3Prompts and Output
  4. 4Application Behavior
  5. 5Safety and Security
  6. 6Operations

Drill it

Reading is not remembering. These come from the Llm Application Design deck:

Q

What is an LLM application?

An LLM application combines a language model with product logic, data, tools, prompts, and user experience to solve a specific workflow.

Q

What is retrieval-augmented generation (RAG)?

RAG retrieves relevant external documents and adds them to model context so answers can use fresh or private knowledge.

Q

Why is grounding important in LLM apps?

Grounding ties model output to provided sources, records, or tool results, reducing hallucinations and making answers easier to verify.

Q

What is prompt injection?

Prompt injection is an attack where untrusted content tries to override instructions, reveal secrets, or force unintended actions.