---
title: "Check the contract between services · Agent Wranglers"
url: https://agentwranglers.se/playbook/testing/integration-and-contract-tests/contract-tests
updated: 2026-10-20
licence: "All rights reserved"
---

# Check the contract between services

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

- Level: Required
- Chapter: [Integration and contract tests](https://agentwranglers.se/playbook/testing/integration-and-contract-tests)
- Rule: When two services you own talk to each other, test the shape of their messages on both sides with a shared contract.
- How: Let the consumer write down the requests it sends and the answers it needs, with a tool such as Pact or a shared schema. Run that contract against the provider in its own build. A provider change that breaks a consumer fails before it ships. Skip this when both sides live in one codebase and always deploy together. To test one API against its OpenAPI file, see [test the API against its contract](https://agentwranglers.se/playbook/api-design/contracts-and-docs/contract-tests).
- Check: Remove a field that a consumer uses from the provider's answer. The provider's build fails on the contract test.

Example:

```js
// Consumer side, Pact JS
await provider.addInteraction({
  states: [{ description: 'order 1042 exists' }],
  uponReceiving: 'a request for order 1042',
  withRequest: { method: 'GET', path: '/orders/1042' },
  willRespondWith: { status: 200, body: { id: 1042, total: 4200 } },
});
```

```python
# Consumer side, pact-python 3 or later
pact = Pact("shop-web", "orders-api").with_specification("V4")
(pact.upon_receiving("a request for order 1042")
    .given("order 1042 exists")
    .with_request("GET", "/orders/1042")
    .will_respond_with(200)
    .with_body({"id": 1042, "total": 4200}, content_type="application/json"))
```

**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 testing playbook: https://agentwranglers.se/playbook/testing/integration-and-contract-tests/contract-tests`.

- Previous: [Fake only what you do not own](https://agentwranglers.se/playbook/testing/integration-and-contract-tests/doubles-at-the-edge)
- Next: [Check that outside services still match your fakes](https://agentwranglers.se/playbook/testing/integration-and-contract-tests/verify-the-fakes)
- [Integration and contract tests](https://agentwranglers.se/playbook/testing/integration-and-contract-tests)
