0PricingLogin
Claude Architect · Lesson

Structured Output

--output-format json with a schema for parsing.

Why Structured Output in CI/CD

When you run Claude Code inside a pipeline, a human is not reading the result — a script is. A CI job needs a stable, machine-parseable answer so it can fail the build, post a comment, or gate a merge.

Two flags make this possible:

  • -p (or --print) runs Claude Code non-interactively — required in any pipeline.
  • --output-format json returns a parseable result instead of free-form text.

This lesson is Domain 4 (Prompt Engineering & Structured Output) meeting Scenario 5 (Claude Code for CI/CD).

claude -p "Review the staged diff for security bugs" \
  --output-format json

The Problem With Free-Form Text

If you let the model answer in prose, your pipeline has to scrape that prose with regexes — counting words, hunting for phrases like "looks good" or "found issues". That is brittle and a classic anti-pattern.

The same rule applies to the agentic loop: you terminate on a stop_reason, never by parsing text for words like "done". In CI, you decide pass/fail from structured fields, never from free text.

Structured output replaces fragile text-scraping with a contract your script can trust.

All lessons in this course

  1. Non-Interactive Mode
  2. Structured Output
  3. Session Isolation for Reviews
  4. Test Generation & Standards
← Back to Claude Architect