Skip to content
Latchkey

Pact "Verification failed" request/response mismatch in CI

The provider replayed each recorded interaction and one response did not match the consumer's expectation. Pact prints "expected ... but received ..." for the exact field, so the contract, not the network, is the problem.

What this error means

Provider verification ends with "Pact verification failed" and a per-interaction diff listing the mismatched status code, header, or body path with "expected ... but received ...".

Pact
Verifying a pact between web-consumer and orders-provider
  A request for order 42
    returns a response which
      has status code 200 (OK)
      has a matching body (FAILED)

Failures:
1) Verifying a pact ... has a matching body
    $.total -> Expected 19.99 but received 20.0

Common causes

The provider response drifted from the contract

A field was renamed, retyped, or its value shape changed on the provider, so the recorded expectation no longer matches what the provider now returns.

An exact value was asserted instead of a matcher

The consumer pinned a literal value (a total, a timestamp) rather than a type matcher, so any differing but valid value fails verification.

How to fix it

Read the diff and align provider or contract

  1. Open the failing interaction and read the "Expected ... but received ..." line.
  2. If the provider change is intended, update the consumer expectation and republish the pact.
  3. If the provider drifted by mistake, fix the provider response to match the contract.
Terminal
# run the provider verification locally against the same pact
./gradlew pactVerify
# or, for JS
npm run test:pact:provider

Use type matchers for volatile values

Assert the shape, not the literal, so valid variation does not break verification.

consumer.pact.spec.js
// consumer test (@pact-foundation/pact)
body: {
  total: Matchers.decimal(19.99),
  createdAt: Matchers.iso8601DateTime(),
}

How to prevent it

  • Prefer type matchers over literal values for anything that varies.
  • Republish the consumer pact whenever the expectation changes.
  • Run provider verification in CI on every provider change.

Frequently asked questions

What causes ""Pact verification failed""?
A field was renamed, retyped, or its value shape changed on the provider, so the recorded expectation no longer matches what the provider now returns.
How do I fix "Pact verification failed"?
Read the diff and align provider or contract

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card