# How should my application parse and validate a structured Claude response?

Exam: CCDV-F — Claude Certified Developer - Foundations
Knowledge domain: Applications and Integration
Updated: 2026-11-25T08:30:13.089851+00:00
HTML: https://learningpathx.com/faq/CCDV-F/ccdvf-validate-structured-output.html

## Also asked as

- What checks should I run before consuming Claude JSON output?
- How do I handle a Claude structured response that is refused, incomplete, or invalid?

Check the API outcome and completion metadata before using the JSON payload. A response with `stop_reason: "refusal"` can return HTTP 200, and `stop_reason: "max_tokens"` can leave JSON incomplete. Route these outcomes to explicit application states. Parse only the documented payload on an accepted completion path. [Claude structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs) [Create a Message](https://platform.claude.com/docs/en/api/messages/create)

Keep the schema version associated with the original request. Extract the expected text payload or use the documented typed SDK helper, then validate against the consumer's contract. Detect missing properties, invalid types, invalid enum values, and unexpected fields. Claude can return a string enum or const with different casing on normal completion. Define unambiguous enum values and normalize only when the consumer contract permits it. Use a standard parser. A parse failure should produce a typed error with safe diagnostics, since guessing at missing JSON can introduce a value the model never returned. [Claude structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs)

Next verify field meaning and combinations. Check that record IDs exist within the caller's authorized scope, cited evidence appears in approved inputs, and any requested transition is legal now. Apply destination-aware escaping to strings, and evaluate confidence-like values before treating them as calibrated evidence. Decide separately whether to display a draft, store a suggestion, or authorize an effect. [Mitigate jailbreaks and prompt injections](https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/mitigate-jailbreaks)

Keep safe correlation metadata and distinguish request configuration errors, refusal, truncation, parse errors, contract errors, and domain errors. Correct configuration errors at their source. Give incomplete output a separately designed continuation or bounded retry policy, and route a semantic failure to review or an evaluated fallback when appropriate. [Claude API errors](https://platform.claude.com/docs/en/api/errors)

Source: [Structured Claude Outputs, Validation, and Defensive Parsing](https://learningpathx.com/news/structured-claude-outputs-validation-and-defensive-parsing.html)
