Check the response contract
Confirm the expected schema, including optional fields, enumerated values, identifiers, and units. A field named “time” may represent seconds, milliseconds, or a formatted date; verify the contract rather than inferring from the name.
Validate at the boundary where the output enters your workflow. Reject or quarantine malformed records with enough context to investigate, while avoiding logs that expose secrets or personal data.
Use data defensively
Apply sensible bounds and consistency checks, such as verifying that a count is nonnegative or that related identifiers refer to the same object. Do not silently replace invalid values with defaults if that could change the meaning.
When a field is absent, choose a documented fallback or mark the result incomplete. Keep validation failures distinct from tool transport errors so the right issue can be corrected.