Manuals / Prompt Engineering / Chapter 8
B · Patterns · intermediate · ~35 min · Chapter 8 of 12
Structured output: JSON mode & schemas
When downstream code consumes model output, free text is fragile. Use JSON mode, schemas, or XML tags for parseable results.
Path progress63%
Step 1 of 2
JSON extraction prompt
Define the exact schema. Ask for JSON only. Validate with a parser.
Example
{
"test_cases": [
{
"id": "TC-001",
"title": "Login with valid credentials",
"steps": ["Navigate to /login", "Enter valid user/pass", "Click Submit"],
"expected": "Dashboard loads"
}
]
}Do this now
Extract test cases from a paragraph into JSON array. Parse with JSON.parse().
Was this step clear?
Chapter learning outcomes
- JSON mode
- Schema validation
- XML tags
Clear these before you leave
Side quest
Bug report extractor
Prompt that turns Slack messages into structured bug reports.