How-to › Test and mock integrations

How to triage a failing spec-driven API test#

Reproduce a red Schemathesis run from its seed and curl line, read the schema branch that failed, and decide whether the spec, the handler or the check is wrong.

Audience
API producer
Level
advanced
Topic
Run contract and spec tests
Languages
Python
Verified

Your Schemathesis job is red with ST108 Response violates schema on POST /orders. The report holds a generated request, a seed, and a curl line. Somebody has to decide whether the document, the handler, or the check is wrong. The quickest edit, loosening the document, makes the job green without answering that question.

What you get

You will end up with the failure reproduced by seed and by hand, traced to one schema path, fixed on the side that was wrong, and proven gone under a fresh seed. This is for you if you own the service and the document it is tested against.

Short answer

Rerun the failure with the seed Schemathesis printed, then send its curl line by hand and confirm the same status and body. Read the response against the schema path the report names. Fix the handler when the document is right, change the document only when the behavior is meant, and accept a failure in a baseline only with an owner and an expires date. Verify with the recorded seed, then a fresh seed and more cases.

You will need

The failing run’s seed and report, the OpenAPI document it used, and a copy of the service you can start. The sample runs Schemathesis from pydeps/, which npm ci fills from a requirements.txt that pins every package to one release and to the SHA-256 of each of its files. Verified 2026-11-30 against Python 3.12.3 and Schemathesis 4.34.4, with Pact Python 4.2.0 and Specmatic 2.55.3 on OpenJDK 21.0.13.1.

Approaches compared

ApproachWhen it fitsWhat it costs youWhen to pick something else
Pact provider verificationKnown consumers publish pacts, and a change should name whom it breaksCovers only interactions some consumer wrote, so an unused operation is never checkedNo consumer writes pacts, or the document is the contract you enforce
SchemathesisYou want requests nobody wrote, shrunk to the smallest one that still failsEvery reproduction depends on the seed, the case budget and the version pinned togetherEach case must be a fixed request that a reviewer can read
SpecmaticEvery case should be a reviewed example file named in the reportA JVM, and one example file per response that goes stale with the serviceYou want inputs found by search, not written by hand

The three hand you a failure in different shapes. Schemathesis gives a minimal generated case, a seed and a curl line, and the input is yours to reproduce. Specmatic names the operation and the example file, so the input is already fixed. Pact names the consumer and the interaction, which tells you who breaks if you change the response instead of the document.

Reproduce the failure from the seed

Schemathesis shrinks a failing input before it reports it. Here the handler answers backordered for more than 50 units, and the report names the smallest quantity that does it.

python3 triage.py red
- ST108 Response violates schema

    "backordered" is not one of "pending", "shipped" or "cancelled"

    Validated against the response schema for status code 201.

    Schema at /properties/status:

        {
            "enum": [
                "pending",
                "shipped",
                "cancelled"
            ],
            "type": "string"
        }

    Value:

        "backordered"

[201] Created:

    `{"id": "ord_0001", "sku": "AAA-000", "quantity": 51, "status": "backordered"}`

Reproduce with:

    curl -X POST -H 'X-Tenant: acme' -H 'Content-Type: application/json' -d '{"quantity": 51, "sku": "AAA-000"}' http://127.0.0.1:42307/orders

Run it again with the same --seed, narrowed to the one operation and the one check, to confirm the case is the seed’s and not chance:

python3 triage.py rerun
curl -X POST -H 'X-Tenant: acme' -H 'Content-Type: application/json' -d '{"quantity": 51, "sku": "AAA-000"}' http://127.0.0.1:41561/orders
❌ ST108 Response violates schema: 1
49 generated, 1 found 1 unique failure
Seed: 1
exit code 1

The same 49 cases and the same minimal request came back. Pin Schemathesis and Hypothesis, which generates its inputs, beside the seed: the seed’s promise covers one setup and nothing more.1

Confirm it by hand

The curl line is the runner’s claim about what it sent. replay sends that request again with http.client and compares the answer with the one in the run’s HAR report.

python3 triage.py replay
runner saw: 201 {"id": "ord_0001", "sku": "AAA-000", "quantity": 51, "status": "backordered"}
replayed:   201 {"id": "ord_0001", "sku": "AAA-000", "quantity": 51, "status": "backordered"}
same status and body: yes

The status and the body match, so the failure belongs to the service. Read the schema path the report names: /properties/status in the 201 response is an enum of three values, and backordered is not one of them.

Compare what Pact and Specmatic report

record.sh ran both tools once against the same unfixed service, with the usage reporting of each switched off. Pact ran with PACT_DO_NOT_TRACK set to true, and Specmatic with disableTelemetry in its specmatic.yaml. The pact, written for this sample, asks for 60 units and expects pending:

cat records/pact.txt
1) Verifying a pact between checkout and orders-service - a bulk order that cannot ship from stock
    1.1) has a matching body
           $.status -> Expected 'backordered' (String) to be equal to 'pending' (String)

The failure names the consumer, checkout, and the interaction it depends on, so changing the response means talking to that team. Specmatic’s report starts from an example file:

cat records/specmatic.txt
Scenario: POST /orders -> 201 with the request from the example 'place_bulk_order_201' where REQUEST.PARAMETERS.HEADER contains the header 'X-Tenant' has FAILED

The input was fixed before the run, so there is no seed to keep. Its rule catalog files the mismatch as R1002.

Decide which side is wrong

The side you blame decides what the fix costs.

The document is wrong when backordered is a real state that consumers should handle. Adding it to the enum turns the job green in minutes, and it moves the contract for every client generated from the document.

The handler is wrong when no consumer was promised that state. That fix is slower, and it keeps the description accurate. Here the corrected handler keeps a large order pending:

    if quantity > STOCK_LIMIT:
        # The bug: a status the document does not list. The fix keeps the order pending.
        status = "pending" if fixed else "backordered"
    else:
        status = "pending"
    return 201, {"id": "ord_0001", "sku": sku, "quantity": quantity, "status": status}

The check does not apply when the behavior is right and the test cannot see why. Schemathesis 4.34.4 records accepted failures in a baseline file, whose documentation says an entry without expires suppresses indefinitely. Give every entry an owner and a date:

python3 triage.py baseline
expires in 30 days
  Known failures: 1
  100 generated, 100 passed
  Seed: 1
  exit code 0
expired yesterday
  Known failures: 0
  ❌ ST108 Response violates schema: 1
  49 generated, 1 found 1 unique failure
  Seed: 1
  exit code 1

Schemathesis reads expires and ignores an owner field. check_baseline.py refuses an entry without one, or with an expiry more than 90 days out, so the rule runs in CI:

python3 check_baseline.py baseline.json
POST /orders response_schema_conformance properties/status/enum: no owner
POST /orders response_schema_conformance properties/status/enum: no expiry date
2 problem(s) in baseline.json

Check it worked

Rerun the fixed handler with the recorded seed, then with a seed the failing run never used and a larger budget:

python3 triage.py fixed
recorded seed
  100 generated, 100 passed
  Seed: 1
  exit code 0
fresh seed, 500 cases
  500 generated, 500 passed
  Seed: 20261130
  exit code 0

The recorded seed shows the reported case is gone. The fresh seed and the larger budget found no other failure in 500 cases. 500 generated, 500 passed is the line to look for. run_tests.py asserts every claim on this page, including the records of the Pact and Specmatic runs.

When it goes wrong

The job fails with ST202 Schema-valid request rejected, and the curl line succeeds when you send it yourself. The runner points at a gateway, and the gateway changed the request on its way in. Diff what the runner sent, from its HAR report,2 against what the service logged:

python3 triage.py gateway
❌ ST202 Schema-valid request rejected: 1
the curl line sent to the service directly: 201
headers the runner sent that the service never received:
  connection: keep-alive
  user-agent: schemathesis/4.34.4
  x-schemathesis-testcaseid: XXXXXX
  x-tenant: acme

The gateway forwards only the headers on its allowlist, and X-Tenant is not on it, so the service answers 400 for a request the document allows. Neither the document nor the handler is wrong. With X-Tenant added to the allowlist, the same run reports no failures. Diff before you blame the document, because loosening it here would hide a gateway setting.

When not to do this

Do not edit the document to make a red run green before you have reproduced the failure by hand. An enum that grows every time a handler invents a value describes the handler, not the contract.

Do not accept a failure without an owner and an expiry date. The baseline file accepts an entry with neither, and that entry stays accepted until someone deletes it.

Do not triage a fuzzing failure against a staging service that other teams write to. A replay there can meet data the generated case never created, and the seed reproduces only the request. Start a copy of the service, as every step here does.

Last verified

Verified 2026-11-30 against Python 3.12.3 and 3.13.18, Schemathesis 4.34.4 and Hypothesis 6.170.24. Every output block is what the command before it printed. triage.py prints a selection of what Schemathesis printed: the failure block, the failure and case counts, and the seed, with the per-run test case id masked as XXXXXX. Pact Python 4.2.0 and Specmatic 2.55.3 ran once in record.sh against the unfixed service, and their reports are committed under records/.

Footnotes

  1. The seed’s contract is modest. Hypothesis documents seed as giving it no exact meaning. It promises only that a fixed value produces the same test cases when nothing else, such as timing, hash randomization, or external state, varies. Its other replay format, the blob @reproduce_failure prints, is not stable across Hypothesis versions. ↩︎ Back to text

  2. The report that settles the argument uses a format with no standard behind it. The HTTP Archive draft, dated August 14, 2012, carries *DO NOT USE* in its status section and says the Web Performance Working Group never published it and abandoned it. Schemathesis 4.34.4 writes it when asked with --report har. ↩︎ Back to text

Read this page as markdown · All how-to guides

Generate the client instead of writing it#

Retries, timeouts, pagination and auth are the same problems in every client. Voxgig generates them from your OpenAPI description, in 23 languages, from one model.

Listen to Fireside, the Voxgig podcast

Since 2018, Richard Rodger has talked with developer advocates, event organizers, and the people who build developer-facing companies about the specifics of the work.