Paths Subjects Questions Quizzes Pricing Search
Advanced Open Pro

Designing a Structured-Output Migration-Risk Extractor

You're building a Python service on the Agent SDK that scans a repo before a migration and returns a risk assessment:

schema = {
    "type": "object",
    "properties": {
        "risk_level": {"type": "string", "enum": ["low", "medium", "high"]},
        "affected_files": {"type": "array", "items": {"type": "string"}},
    },
    "required": ["risk_level", "affected_files"],
}

passed via output_format={"type": "json_schema", "schema": schema}.

  1. Claude's first attempt returns risk_level: "moderate" (not one of the enum values). What does the SDK do next, and what would a naive implementation that just checked message.structured_output is not None get wrong in this specific failure?
  2. Give one concrete reason a ResultMessage could have subtype == "success" but no structured_output at all, distinct from a schema-validation failure.
  3. Your team is deciding between this SDK approach and claude -p --output-format json --json-schema '<schema>' invoked as a subprocess for the same task. Name one capability difference between the two that specifically affects how often this "moderate" mistake would make it into your database.

Share this question

← Back to Headless Mode, CI Automation & the Agent SDK practice

We use cookies for product analytics to improve OmniAtlas. See our Privacy Policy.