# 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.

Source: https://voxgig.com/howto/triage-a-failing-spec-driven-api-test

- Audience: api-producer
- Level: advanced
- Languages: python
- Verified: 2026-11-30
- Published: 2026-11-30

## 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

| Approach | When it fits | What it costs you | When to pick something else |
| --- | --- | --- | --- |
| [Pact provider verification](https://docs.pact.io/getting_started/verifying_pacts) | Known consumers publish pacts, and a change should name whom it breaks | Covers only interactions some consumer wrote, so an unused operation is never checked | No consumer writes pacts, or the document is the contract you enforce |
| [Schemathesis](https://schemathesis.readthedocs.io/en/stable/reference/cli/) | You want requests nobody wrote, shrunk to the smallest one that still fails | Every reproduction depends on the seed, the case budget and the version pinned together | Each case must be a fixed request that a reviewer can read |
| [Specmatic](https://docs.specmatic.io/features/external_examples) | Every case should be a reviewed example file named in the report | A JVM, and one example file per response that goes stale with the service | You 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.

```bash
python3 triage.py red
```

```text output
- 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`](https://schemathesis.readthedocs.io/en/stable/reference/cli/#-seed-integer),
narrowed to the one operation and the one check, to confirm the case is the seed's and not
chance:

```bash
python3 triage.py rerun
```

```text output
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.

```bash
python3 triage.py replay
```

```text output
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`](https://docs.pact.io/implementation_guides/python/readme) set to `true`, and
Specmatic with [`disableTelemetry`](https://docs.specmatic.io/references/configuration/telemetry)
in its `specmatic.yaml`. The pact, written for this sample, asks for 60
units and expects `pending`:

```bash
cat records/pact.txt
```

```text output
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:

```bash
cat records/specmatic.txt
```

```text output
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](https://docs.specmatic.io/rules) 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`:

```python title="service.py"
    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](https://schemathesis.readthedocs.io/en/stable/guides/baseline/), whose
documentation says an entry without `expires` suppresses indefinitely. Give every entry an owner
and a date:

```bash
python3 triage.py baseline
```

```text output
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:

```bash
python3 check_baseline.py baseline.json
```

```text output
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:

```bash
python3 triage.py fixed
```

```text output
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:

```bash
python3 triage.py gateway
```

```text output
❌ 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.

## Related how-tos

- [Run an OpenAPI document as a contract test with Specmatic](/howto/openapi-as-a-contract-test-with-specmatic)

- [Choose consumer-driven or spec-driven contract tests](/howto/choose-consumer-driven-or-spec-driven-contract-tests)

- [Validate responses against the OpenAPI document at runtime](/howto/validate-responses-against-the-openapi-document)

- [Test stateful endpoints with Dredd hooks](/howto/stateful-api-tests-with-dredd-hooks)

- [Intercept fetch calls in browser tests with MSW](/howto/intercept-fetch-in-browser-tests-with-msw)

## 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/`.

[^1]: The seed's contract is modest. Hypothesis
[documents `seed`](https://hypothesis.readthedocs.io/en/latest/reference/api.html#hypothesis.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](https://hypothesis.readthedocs.io/en/latest/tutorial/replaying-failures.html).

[^2]: The report that settles the argument uses a format with no standard behind it. The
[HTTP Archive draft](https://webperfwg.org/specs/HAR/Overview.html), 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`.