Write prompts that return reliable structured output
8 steps · about 2 h 5 min · Beginner
- Learn the parts of a prompt (guide, Prompt Engineering Guide, 10 min)
Instruction, context, input and output format are the pieces you will adjust in every later step.
- Make instructions specific and testable (guide, Prompt Engineering Guide, 15 min)
Vague requests produce vague answers; state the task, audience, length and format explicitly.
- Separate instructions from data with tags (doc, Anthropic, 10 min)
Clear delimiters stop the model from confusing your instructions with the text it is asked to process.
- Show the format with a few examples (guide, Prompt Engineering Guide, 15 min)
Two or three worked examples fix the output shape far more reliably than a description alone.
- Ask for reasoning before the answer (guide, Prompt Engineering Guide, 15 min)
Letting the model work through steps improves multi-step tasks; keep the reasoning separate from the final field.
- Describe the output with a JSON schema (tutorial, JSON Schema, 15 min)
A schema turns 'return JSON' into a precise contract for field names, types and required values.
- Validate every response in code (doc, Pydantic, 25 min)
Parse each reply into a typed model so malformed or missing fields fail loudly instead of corrupting your data.
- Guard the prompt against injected instructions (guide, Prompt Engineering Guide, 20 min)
User-supplied text can try to override your instructions; learn the common attacks and practical defences.