Question 360
A customer record extractor returns an object with id as text even though the consumer expects an integer. Which schema field should prevent the mismatch?
Explanation
Correct Answer
The schema should express the consumer’s actual data contract, so a genuinely numeric id property must declare integer rather than string. Validate the parsed value against that type and the relevant business constraints before passing it to downstream code; do not rely solely on prompt examples or global coercion. If the source identifier may contain leading zeros or nondecimal characters, revisit the consumer contract because it might actually be a string. This case assumes an integer identity by design, and the correct repair is to enforce that field’s type explicitly while retaining independent factual verification of the value itself.
Incorrect Answers
A Markdown example saying id should be an integer is documentation, not a machine-enforced JSON Schema contract. The consumer still sees a declared string type, so a model may emit "123" and pass the wrong check. When the application truly requires a numeric identifier, the schema should declare integer at the corresponding property and validate the parsed result. Separate that requirement from identifiers such as postal codes, where leading zeros make strings appropriate. An illustrative example cannot replace an explicit type constraint.
Implicit coercion may make one malformed object parseable but can change identifier meaning or erase significant formatting. The consumer contract expects an integer here, but the fix requires a validated schema or an explicit, safe conversion rule with range checks. Blind coercion is not a reliable substitute for requesting a correctly typed field and testing that the resulting record preserves source identity.
Coercing every string to an integer can corrupt names, addresses and identifiers whose leading zeros or punctuation carry meaning. It also hides a schema mismatch by silently converting unexpected inputs instead of reporting them. Type enforcement should be field-specific: declare id as integer only if the consumer contract truly treats it numerically, and preserve strings for text-bearing fields. Recheck source values and the parsed type before allowing downstream writes; blanket conversion is neither precise validation nor safe data normalization.



Claude Certified Architect - Foundations (CCA-F) Practice Tests