---
title: "Test the API against its contract · Agent Wranglers"
url: https://agentwranglers.se/playbook/api-design/contracts-and-docs/contract-tests
updated: 2026-10-20
licence: "All rights reserved"
---

# Test the API against its contract

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Contracts and docs](https://agentwranglers.se/playbook/api-design/contracts-and-docs)
- Rule: Run tests that send requests and validate every response against the contract.
- How: Use a contract testing tool, such as Schemathesis or a validating proxy such as Prism, or validate responses in your own end-to-end tests. Run them in the build before every deploy. An endpoint that follows an outside protocol, such as MCP or JSON-RPC, uses that protocol's schema as its contract instead.
- Check: Change a field's type in the code on a branch. The contract tests fail.

Example:

```sh
schemathesis run openapi.yaml --url https://staging.example.com --checks all
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers api design playbook: https://agentwranglers.se/playbook/api-design/contracts-and-docs/contract-tests`.

- Previous: [Write the contract first](https://agentwranglers.se/playbook/api-design/contracts-and-docs/openapi-contract)
- Next: [Give every endpoint an example](https://agentwranglers.se/playbook/api-design/contracts-and-docs/examples)
- [Contracts and docs](https://agentwranglers.se/playbook/api-design/contracts-and-docs)
