Best Practices for Building LLM Apps

Chapter 1 · Practice 1 of 4

Write specific instructions with the context a new colleague would need

From Prompt design and structured output

Why it matters

Models do what you ask, not what you meant. A vague prompt leaves the model to guess, and guesses are what break in production.

Spell out four things in every prompt:

  • The task: what the model should produce.
  • The audience: who reads the result.
  • The format: length, structure, fields.
  • The edge cases: what to do when the input does not fit, such as "if the document has no date, return null".

Put stable instructions in the system prompt and the changing input in the user turn. Wrap long inputs in clear delimiters, such as XML-style tags, so the model can tell instructions from data.

When tone or format matters, add two or three short examples of good output. Make the examples varied, so the model learns the pattern instead of copying one of them.

A useful test: hand the prompt to a teammate with no background. If they would ask a clarifying question, the model will guess instead. Answer that question in the prompt.

Do

  • Say what to do when input is missing or ambiguous
  • Wrap long inputs in clear delimiters such as XML-style tags

Avoid

  • Stacking capital-letter warnings instead of explaining the reason