Show answerHide answer
Correct answer: D Apply defensive parsing to handle unexpected fields, missing values, and type mismatches that the downstream code might otherwise crash on.
Explanation
ExplanationThe goal is to prevent malformed or unexpected output from crashing downstream systems. Defensive parsing is the right tool: it treats the model's output as untrusted input and normalizes it before downstream code consumes it. Concretely, it:
- Tolerates unexpected fields — ignores or quarantines fields not in the schema rather than failing.
- Handles missing values — substitutes safe defaults, marks them explicitly, or routes them to a repair or fallback path.
- Coerces or rejects type mismatches — for example, a string where a number is expected gets parsed or flagged rather than passed through to crash the consumer.
Combined with validation, which detects the problem, and repair or fallback, which recovers, defensive parsing forms the boundary layer that makes the integration resilient. Malformed output becomes a handled condition, not an outage. ✅
Why the other options are incorrect
A — "Crash on any unexpected output; require manual recovery": This is exactly the failure mode being avoided. One unexpected field takes down requests and demands manual intervention, which doesn't scale.
B — "Silently drop non-matching output": Prevents a crash but creates silent data loss. Downstream systems receive incomplete or missing data without any signal, which can be worse than a visible failure and hides defects.
C — "Use the output as-is; defer schema enforcement": This is a direct cause of downstream crashes because untrusted, unvalidated output reaches consumers. Deferring enforcement doesn't remove the risk; it simply moves the failure into production.
References
- Anthropic structured-output and tool-use guidance — validate and defensively handle model output before downstream consumption.