Pinning Claude Model IDs and Upgrading Safely: One Change at a Time, a Golden-Set Replay and a Staged Rollout
Pin the exact Claude model ID, keep prompts in versioned files, change one thing per release, then earn a model switch: replay a golden set, read the deltas, fix the request for the newer model and roll out in stages.
What you will learn
- Pin an exact Claude model ID in one place and refuse floating names
- Keep each prompt version in its own file and change only one of model or prompt per release
- Replay a golden set on the pinned model and the candidate, and read errors, broken and fixed cases separately
- Stage a model switch through shadow, canary, half and full, with a rollback gate
Before you start
- The Claude Messages API: your first call
- Why you cannot ship an LLM feature without an eval
A support agent labels tickets all day. One morning the same ticket gets a different label. What changed? Two things decide what Claude answers: the model and the prompt. If you can't say which of the two moved, you can't fix it.
This article covers both halves of that problem. First, how to pin the model and version the prompt so every change has a cause. Then, how to move to a newer model when your pinned one is being retired, without guessing: replay a golden set, read the deltas, and roll out a small share first.
A cake, a recipe and an oven
Think of baking a cake. The recipe card is the prompt. Give it a number, recipe one, recipe two, and keep every version as its own file. The oven is the model ID. Name the exact oven, so it can't change under you.
Now change both on the same night. The cake tastes odd, and you can't say which change did it. So you change one, then bake. Name the recipe, name the oven, change one.
Every model ID is a fixed snapshot
According to the Claude docs, a model ID names a pinned version of the model:
- Current IDs have no date in them.
claude-sonnet-5-5is one fixed snapshot. A new version ships under a new ID. - Older models also had an alias, which points to the newest dated snapshot, so it can move.
- A dated ID names its snapshot with a date and stays fixed.
So dateless doesn't mean "latest", and every ID has its own retirement date. In your config, pin the exact ID, never a name that can move.
config.py: one exact ID, one prompt version
The project is a tiny ticket triage. The release lives in one file, app_config.json:
{
"model": "claude-sonnet-5-5",
"prompt": "triage",
"prompt_version": "v1",
"max_tokens": 100
}
The loader refuses any model ID the team hasn't tested:
"""Release settings: one exact model ID and one prompt version."""
import json
import pathlib
HERE = pathlib.Path(__file__).parent
TESTED = {"claude-sonnet-5-5", "claude-haiku-5-5"}
def check_pinned(model):
"""Only an exact model ID we have tested may ship. No alias, no latest."""
if model not in TESTED:
raise ValueError(f"{model!r} is not a tested model ID")
return model
def load(**change):
cfg = json.loads((HERE / "app_config.json").read_text())
cfg.update(change)
check_pinned(cfg["model"])
return cfg
TESTEDlists full model IDs. Anything else, an alias or a typo, raises before a single call is made.- A change comes in as one named override, like
load(prompt_version="v2"). - The check runs every time a release loads.
triage.py: every answer names its model and prompt
Each prompt version is its own file, triage_v1.txt and triage_v2.txt. The call reads the file the config names, and the answer carries the model that served it:
"""One triage call. The answer carries the model ID and prompt version behind it."""
import hashlib
import pathlib
HERE = pathlib.Path(__file__).parent
def version_name(cfg):
return f"{cfg['prompt']}_{cfg['prompt_version']}"
def prompt_text(cfg):
return (HERE / f"{version_name(cfg)}.txt").read_text().strip()
def release_id(cfg):
digest = hashlib.sha1(prompt_text(cfg).encode()).hexdigest()[:6]
return f"{cfg['model']} + {version_name(cfg)} ({digest})"
def triage(ticket, client, cfg):
r = client.messages.create(
model=cfg["model"],
max_tokens=cfg["max_tokens"],
system=prompt_text(cfg),
messages=[{"role": "user", "content": ticket["text"]}],
)
return {"id": ticket["id"], "label": r.content[0].text.split(" | ")[0],
"served_by": r.model}
release_idputs the model and the prompt version in one label, with a short hash of the prompt text that proves which words were used.served_bycomes fromr.modelin the response, so a log line can always name the model.
Same tickets, three releases
run_all.py runs three tickets through three releases: model and prompt changed together, then only the prompt, then only the model. The project runs against a stand-in (the real Anthropic SDK on an httpx mock transport), so the labels are scripted for the demo, not real model behaviour.
bundled change: model and prompt together
before claude-sonnet-5-5 + triage_v1 (34a6f5)
served by claude-sonnet-5-5: T-1 billing T-2 bug T-3 account
after claude-haiku-5-5 + triage_v2 (ee59a8)
served by claude-haiku-5-5: T-1 billing T-2 account T-3 billing
changed: T-2 T-3 -> the model or the prompt? unknown
one change at a time
prompt only claude-sonnet-5-5 + triage_v2 (ee59a8)
served by claude-sonnet-5-5: T-1 billing T-2 bug T-3 billing
changed: T-3 -> the prompt
model only claude-haiku-5-5 + triage_v1 (34a6f5)
served by claude-haiku-5-5: T-1 billing T-2 account T-3 account
changed: T-2 -> the model
a floating name
rejected: 'claude-sonnet-latest' is not a tested model ID
The bundled release moved T-2 and T-3, and nobody can say why. Changed one at a time, the prompt moved T-3 and the model moved T-2. Only a single change lets the difference point at its cause. And the floating name is refused before any call.
Keeping prompts in files with a version and a test is a habit of its own; prompt versioning and testing in a repo covers the registry and golden-set scoring side in more depth.
When the pinned model is being retired
Now the second half. A SupportDesk reply job is pinned to Claude Sonnet 4.5 by its exact ID. A retirement notice arrives. The Claude docs (Model deprecations) say Anthropic gives at least 60 days of notice for publicly released models, and the notice names a replacement. Here that's Claude Sonnet 5.5.
The tempting move is to change the ID and ship. But the request may return a 400, the answers may shift, and there's no way back. The notice gives you time. Use it to test.
Back to the kitchen: a bakery that changes its flour supplier names the flour by its exact product code (the pin), runs a taste test with the same dishes on old and new flour (the golden set), and puts the new flour into one kitchen first (the staged rollout).
pins.py: the candidate sits beside the pin
"""One place that names the model for each job."""
from stand_in import OLD_SONNET, SONNET, HAIKU, OPUS
KNOWN = {OLD_SONNET, SONNET, HAIKU, OPUS}
PINS = {"reply": OLD_SONNET}
CANDIDATES = {"reply": SONNET}
def check(model_id):
"""Refuse a floating or misspelled id."""
if model_id not in KNOWN:
raise ValueError(f"unpinned model id: {model_id}")
return model_id
def model_for(job):
return check(PINS[job])
The reply job names one exact ID. The candidate sits beside it and never replaces the pin until the checks say so. In the stand-in, OLD_SONNET is claude-sonnet-4-5 and the newer models are claude-haiku-5-5, claude-sonnet-5-5 and claude-opus-5-5.
The same request may not work on the newer model
A switch is a code change too. The Claude Sonnet 5.5 migration guide lists several request shapes that newer models reject, and the project's request.py shows the request sent today next to the one the newer model accepts:
"""The request we send today, and the request a newer model accepts."""
SYSTEM = 'Reply with JSON only: {"label": "<answer>"}'
def old_request(model, case):
"""Prefill, a thinking budget and temperature."""
return dict(
model=model, max_tokens=512, system=SYSTEM,
messages=[{"role": "user", "content": case["text"]},
{"role": "assistant", "content": "{"}],
extra_body={"temperature": 0,
"thinking": {"type": "enabled", "budget_tokens": 1024}})
def new_request(model, case):
"""No prefill, no budget, no temperature. Effort sets depth."""
return dict(
model=model, max_tokens=512, system=SYSTEM,
messages=[{"role": "user", "content": case["text"]}],
output_config={"effort": "medium"})
- Assistant prefill (the trailing
{"role": "assistant", "content": "{"}) returns a 400. Use structured outputs or a system prompt instead, depending on what the prefill was for. - A thinking budget (
budget_tokens) returns a 400. Use adaptive thinking and an effort level you choose. temperature,top_pandtop_k: leave them out.- The reply can start with a thinking block, so read each content block by its
type, not by position.
evalrun.py: replay, then read the deltas
The golden set is six fixed tickets with the label each one should get (refund status, cancel, billing, account, escalate, order change). evalrun.py sends each case to one model and tags the result:
"""Replay the golden set on a model, then read the deltas."""
import json
import anthropic
def label_of(resp):
text = next(b.text for b in resp.content if b.type == "text")
return json.loads(text)["label"]
def run_set(client, model, build, cases):
"""Return pass, fail or error for each case."""
out = {}
for case in cases:
try:
resp = client.messages.create(**build(model, case))
except anthropic.BadRequestError:
out[case["id"]] = "error"
continue
ok = label_of(resp) == case["expect"]
out[case["id"]] = "pass" if ok else "fail"
return out
def tag(base, cand):
if cand == "error":
return "error"
if base == "pass" and cand == "fail":
return "broken"
if base == "fail" and cand == "pass":
return "fixed"
return "same"
def deltas(base, cand):
return {cid: tag(base[cid], cand[cid]) for cid in base}
def verdict(delta):
tags = list(delta.values())
if "error" in tags:
return "hold: fix the request first"
if "broken" in tags:
return f"hold: {tags.count('broken')} broken"
return "go: shadow first"
label_ofskips the thinking block and reads the firsttextblock.- A 400 (
anthropic.BadRequestError) counts as an error, not a wrong answer. The report keeps the two apart. - A case that passed before and fails now is broken. One that failed before and passes now is fixed.
- Any error holds the switch, because the request must be fixed before the answers mean anything. So does any broken case.
stage.py: a small share first, then more
Passing the golden set earns a staged rollout, not a full one:
"""Stage the rollout: a small share first, then a gate per step."""
import zlib
STAGES = [("shadow", 0), ("canary", 5), ("half", 50), ("full", 100)]
def use_candidate(request_id, percent):
"""The same request id always lands on the same side."""
return zlib.crc32(request_id.encode()) % 100 < percent
def share(stage, count=200):
pct = dict(STAGES)[stage]
ids = (f"req-{i}" for i in range(count))
return sum(use_candidate(r, pct) for r in ids)
def advance(stage, report):
"""Step up only on a clean report. Otherwise back to the pin."""
if report["errors"] or report["must_pass_failed"]:
return "rollback"
names = [name for name, _pct in STAGES]
return names[min(names.index(stage) + 1, len(names) - 1)]
Hashing the request id means the same request always lands on the same side. Before each step up, the gate looks at errors and must-pass misses. A miss sends all the traffic back to the pin. Rollback is simple because the pin still names the model that was serving. The shadow, canary and rollback pattern itself is covered in depth in shadow, canary and rollback for a model release.
What the run printed
All answers are scripted test data from the stand-in, not a measure of any real model. The 400 rules in the stand-in follow the Sonnet 5.5 migration guide.
pins
reply -> claude-sonnet-4-5 (pinned)
refused: unpinned model id: claude-sonnet
replay
claude-sonnet-4-5 old request: 5/6 pass
claude-sonnet-5-5 old request: 0/6 pass, 6 errors
claude-sonnet-5-5 new request: 6/6 pass
deltas
g1 pass -> pass same
g2 pass -> pass same
g3 pass -> pass same
g4 fail -> pass fixed
g5 pass -> pass same
g6 pass -> pass same
verdict: go: shadow first
old request: hold: fix the request first
haiku: hold: 1 broken
rollout
shadow 0% 0 of 200 on candidate
canary 5% 10 of 200 on candidate
half 50% 105 of 200 on candidate
full 100% 200 of 200 on candidate
canary clean -> half
canary must-pass miss -> rollback
tiers
route -> claude-haiku-5-5 decided by latency budget
escalate -> claude-sonnet-5-5 decided by must-pass accuracy
review -> claude-opus-5-5 decided by task depth
- The pinned model sets the baseline: 5 of 6.
- The old request on the candidate gives 6 errors. That's the request, not the model.
- The new request passes 6 of 6. Only g4 changed, from fail to pass. Nothing broke, so the verdict is "go: shadow first".
- A smaller tier on the same cases breaks one, so that switch is on hold.
- The rollout counts how many of 200 requests reach the candidate at each stage. A clean canary moves up to half; a must-pass miss rolls back.
One constraint decides the tier
The last block of the run, from decide.py, picks a tier for three jobs and names the single constraint that ruled the other tiers out:
| Job | Pick | Deciding constraint |
|---|---|---|
| Route a ticket | Haiku | Latency budget: Haiku passes the cases and only the fastest tier fits |
| Spot "I will sue" and escalate | Sonnet | Must-pass accuracy: Haiku misses that case |
| Review a policy against 12 checks | Opus | Task depth: in this data only Opus clears all 12 |
These picks come from the scripted demo data. With your own golden set, the numbers will differ, but the habit is the same: name the one constraint that decided.
Common mistakes
- Using an alias so it "always updates". An alias can move to a new snapshot under you. Pin the exact ID.
- Editing the prompt in place. Then there's no version to go back to. Add a new file.
- Shipping a new model and a new prompt together. That hides which change did it.
- Changing the ID and watching the dashboards. No baseline, no deltas. Replay the golden set first.
- Counting a 400 as a wrong answer. Errors mean the request needs fixing for the new model. Keep them apart from broken cases.
- Picking the biggest tier to be safe. It ignores the constraint that actually binds, such as latency or cost.
Quick recap
| Step | What you do |
|---|---|
| Pin | One exact model ID in one config file; refuse anything not tested |
| Version | One file per prompt version; log model and prompt version with every answer |
| Change one | Model or prompt per release, compared on the same tickets |
| Replay | The golden set on the pinned model and on the candidate |
| Read deltas | Errors, broken and fixed, read separately; any error or break holds the switch |
| Stage | Shadow, canary, half, full, with a gate and a rollback to the pin |
Try it yourself
Add a seventh golden case to the triage set that only the newer prompt gets right. Run the "prompt only" release and check that the delta names the prompt as the cause. Then try loading claude-sonnet-latest and confirm it's refused before any call.
Related course on Udemy
Claude Certified Developer - Foundations (CCDV-F) Exam Prep
Build and ship Claude apps: the API, agents, tools and MCP, prompts, evals, security and model choice.View on Udemy ↗: Claude Certified Developer - Foundations (CCDV-F) Exam Prep (paid course, opens in a new tab)Related posts
The Claude Messages API: Your First Call, Field by Field
One request in, one Message out. The four fields of a Messages API call (model, max_tokens, system, messages), how to read content blocks, stop_reason and usage, and why every turn resends the history.
Claude Tool Use: How tool_use and tool_result Work in the Messages API
Follow one order question through Claude's tool round trip: define a tool, read the tool_use block, run your own function and send a matching tool_result back, including parallel calls and is_error.
Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
Every Claude client SDK wraps the same REST request: a POST to /v1/messages with a JSON body. See it built by hand, through the Python and TypeScript SDKs, as typed errors, and as async calls that wait together.
Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
Configure the Anthropic SDK client (timeout, max_retries, with_options, async, pagination), see which errors it retries by itself, then repair a retry wrapper so a 429, a 529, a 400 and a timeout each get the move the docs support.