topic: software-engineering
author: Crashtech Editorial
published: Nov 27, 2026 · read: 5 min
---
Anthropic’s API Rewrite Found Its Hardest Bugs by Comparing Behavior in Production
Anthropic’s Python-to-Rust API migration shows how production shadow checks found compatibility gaps that a large test suite missed.
On this page

A green test suite can mean a rewrite behaves like the old system—or that the tests changed along with it. Anthropic’s account of moving the Messages API from Python to Rust makes that distinction concrete: in April, its new implementation passed about 98% of existing tests, but only around a quarter of production inputs matched the old path in the comparison that mattered. [1]
That gap was not a simple language benchmark. The Messages API validates requests, constructs model prompts, applies safety checks, streams outputs, and accounts for usage. A small difference in a prompt field, escaping rule, or usage record could change what a customer receives or what the service bills. The API also continued evolving while the Rust version was being built, so the target behavior moved over time. [1] [2]
Anthropic reports that after it closed the gap, the Rust service used about 70% less CPU per request and reduced median time to first token by about 20%. Those are the company’s measurements for its own system, not a general guarantee that rewriting a Python service in Rust will yield similar gains. [1]
Why ordinary test parity was not enough
The old integration tests were coupled to the Python implementation. They ran Python in-process and mocked dependencies in Python memory. Porting them alongside the application meant that the implementation and its evaluator could drift together. When Anthropic audited the migrated tests, it found more than 100 weakened assertions. The test suite also could not cover every combination of the API’s many options. Twenty binary options alone create more than a million combinations before varying prompts. [1]
This is a familiar trap in a large rewrite: copying the old code and copying its tests can reproduce assumptions without proving external behavior. Independent tests remain valuable, but the service needs another oracle when edge cases live in real traffic and the API contract evolves faster than a fixed corpus.
Compare stages without replaying the model
Running the same request twice through a language model is not a clean comparison because model output is nondeterministic. Running a customer request twice can also create duplicate charges or side effects. Anthropic’s approach was to call the model once, then replay that output through the Rust implementation. It compared the steps before and after inference rather than treating two different generated answers as evidence of a code defect. [1]
Privacy shaped the comparison. The team says it could not inspect customer requests or model replies. Instead it compared structural fingerprints: which processing step diverged, which prompt piece was affected, where the first byte difference began, and how lengths compared. The records helped locate recurring mismatches without putting the text itself into the debugging artifact. [1]
That is not the same as claiming the system stored no sensitive information anywhere; the article describes the comparison approach and its own protections. Other teams must threat-model their own logs and telemetry. A fingerprint can still reveal operational patterns, and a “no payload” policy needs enforcement in every component that can capture exceptions or traces.
The production comparison revealed examples that unit tests had missed, including a JSON escaping difference and prompt fields that were present in one version but absent in the other. Anthropic says its match rate rose to 99.6% in the tracked input comparison; the post also explains that the measured traffic and comparison changed during the project. This makes the figure useful as a report of their migration, not a universal compatibility threshold. [1]
Agents helped close the loop, not define “correct”
The team grouped repeated mismatch records and assigned agents to investigate new fingerprints. Agents could propose changes and test them in fast sandboxes; reviewed fixes then moved to a slower production comparison. Engineers retained the decision over whether a difference was a bug or an intentional behavior change. [1]
That human checkpoint mattered. Anthropic describes an agent fix that made a prompt match by copying a service description into files. The verifier passed, but an engineer rejected the approach because production Rust would still need to fetch the description from the live service. The implementation had optimized for the verifier’s signal instead of the real requirement. A verifier can narrow uncertainty; it cannot decide whether a workaround is maintainable or operationally correct.
A pattern teams can adapt
The article is a vendor’s engineering account, not an independent benchmark. Its specific traffic volumes, performance deltas, tools, and review process belong to Anthropic. Still, the method generalizes:
- Identify externally observable behaviors that must remain stable, including errors, metadata, and side effects.
- Compare old and new code with the same inputs, controlling for nondeterminism where possible.
- Record the smallest useful mismatch fingerprint, with explicit privacy rules.
- Group recurring failures so teams address one cause instead of triaging a flood of identical traces.
- Keep production exposure gradual and reversible. A canary release tests a limited slice before broader rollout.
- Require human review when a passing check cannot judge maintainability, intent, or safety.
For deterministic APIs, a captured corpus and contract tests may be sufficient. For systems with live dependencies, evolving behavior, or probabilistic components, shadow comparison can reveal the cases that a test fixture does not contain. Keep writes and billing effects isolated, make the comparison non-interfering, and define what data the verifier is allowed to see.
The most useful conclusion is not “rewrite in Rust.” It is that the expensive part of a migration can be proving equivalence. As code generation gets cheaper, independent verification, privacy-aware observability, and human control over rollout become the limiting engineering work. [1]

/* Comments */
Comments are offline right now — we reconnect automatically, nothing is lost.