Skip to content
Latchkey

Pact "Verification failed" provider/consumer mismatch in CI

Pact replayed the consumer's expected interactions against the running provider and one or more responses did not match the contract. It reports the mismatched interaction with the expected versus actual body, headers, or status.

What this error means

Provider verification fails with "Verification failed" and a mismatch list showing an expected field or status the provider did not return.

Pact
Verifying a pact between web-consumer and user-api
  Given a user with id 1 exists
    a request for user 1
      returns a response which
        has status code 200 (OK)
        has a matching body (FAILED)

Failures:
1) Verifying a pact ... has a matching body
   $.name -> Expected "Ada" but received "Ada Lovelace"

Common causes

The provider changed its response shape

The provider now returns a different field, type, or status than the published contract expects, so verification fails.

Missing provider state setup

The "Given" provider state was not set up (data not seeded), so the provider returns a body that does not match the interaction.

How to fix it

Reconcile the provider with the contract

  1. Read the mismatch: expected versus actual for the named field or status.
  2. Either fix the provider to honor the contract, or update the consumer test and republish.
  3. Implement the provider state so the seeded data matches the interaction.

Wire up provider states

Register a state handler that seeds the exact data the "Given" clause names before the interaction is replayed.

Java
stateHandlers.put("a user with id 1 exists",
  () -> repository.save(new User(1, "Ada")));

How to prevent it

  • Run provider verification in CI on every provider change.
  • Implement provider states so seeded data matches each interaction.
  • Coordinate contract changes with the consumer before merging.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →