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 progress
63%

Step 1 of 2

JSON extraction prompt

Define the exact schema. Ask for JSON only. Validate with a parser.

JSON extraction promptDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →JSON extraction prdrag · tap →Try thisdrag · tap →Follow the dashed drag · tap →

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.