Agent Wranglers

API-10Recommended

Give every response one shape

Return the same fields of the same types every time, and describe them in the contract. Leave out a field only when the contract says it is optional.

How to do it

Decide per field whether it is required. Never switch a field between an object, a list and null. See one return type. Return only the fields a caller may see, as in only needed fields.

How to check

Contract tests validate every response against its schema with additionalProperties: false, and they pass. Schemas built with allOf use unevaluatedProperties: false instead, because additionalProperties can't see fields from the other parts.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/requests-and-responses/response-shape">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.