Skip to content

About

Static checks for LLM API calls that break when providers change model behavior (Claude 5 drift: sampling params, thinking blocks, forced tool_choice...)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

llm-drift-lint

Static checks for LLM API calls that break when providers change model behavior.

LLM providers change what their models accept faster than client code changes. Every rule here comes from a bug that shipped in a real open-source project and was fixed upstream, often after it had already broken every request for users on current models:

  • temperature: 0.0 sent by default to models that now reject it;
  • response.content[0].text read when the first block is now a thinking block;
  • forced tool_choice sent to models that reject it while thinking;
  • manual budget_tokens sent to models that only take effort levels;
  • a default model that its provider has already shut down, or will next week;
  • streamed tool calls merged by an index that Gemini never sends.

The linter reads your Python source, finds the SDK calls, resolves the model id when it's a literal or a constant, and checks the call against what that model accepts.

Status: v0.5. LDL001–LDL006 target the Anthropic Python SDK (direct, Bedrock and Vertex model ids); LDL007–LDL012 extend it to OpenAI and Gemini: retired default models, OpenAI-compatible stream reducers, OpenAI→Anthropic gateways and OpenAI/Gemini sampling parameters. LDL013–LDL018 cover usage, refusals and finish reasons: Gemini thinking tokens left out of the output count, stop-reason maps that miss what Claude and Bedrock now return, Anthropic stream handlers that drop the cumulative input and cache counts of message_delta, cached tokens left out of an input count, OpenAI refusals lost in conversion, and Gemini blocking finish reasons not treated as a content filter. They were chosen from the recurring patterns in merge-log-data.

Rules

Id Name Flags Real-world fix that motivated it
LDL001 anthropic-sampling-params a non-default temperature / top_p / top_k (or temperature and top_p together) sent to a model that rejects them langchainrb#1055, WeKnora#4155, trulens#2948
LDL002 anthropic-sampling-kwargs-sdk1 sampling parameters passed as keyword arguments to messages.create() in a project on anthropic>=1, where they are no longer keyword arguments phoenix#17026
LDL003 content-first-block-text response.content[0].text, where block 0 can be a thinking block reward-bench#290, hostedgpt#823
LDL004 forced-tool-choice tool_choice={"type": "tool" | "any"} sent to a model that rejects a forced tool choice phoenix#17027, ha-llmvision#747
LDL005 thinking-budget-tokens thinking={"type": "enabled", "budget_tokens": N} sent to a model that takes effort levels instead chatlas#448
LDL006 low-max-tokens-thinking max_tokens ≤ 1024 sent to a model that thinks by default, so thinking can use the whole budget and the answer comes back empty langchainrb#1073, livekit/agents#7726
LDL007 retired-model-default a default model (parameter default, *MODEL* constant, env-var or CLI fallback) that OpenAI, the Claude API, the Gemini API or Vertex AI has shut down or has scheduled for shutdown; Vertex's own Gemini dates apply only to code that targets Vertex OpenAI, Claude, Gemini API and Vertex AI deprecation pages
LDL008 incomplete-sampling-gate a hand-written Claude model check that drops temperature / top_p / top_k for some of the models that reject them, but not all gpt-researcher#2217, fabric#2270, cherry-studio#21939, kiss-translator#1185
LDL009 incomplete-thinking-gate a hand-written Claude model check that still sends budget_tokens to models that only take adaptive thinking fabric#2270
LDL010 stream-tool-call-index a streamed tool-call reducer keyed by tool_calls[].index with no usable fallback; Gemini's OpenAI-compatible endpoint omits index, so parallel calls collapse into one or are dropped Gemini OpenAI compatibility; upstream fixes in review
LDL011 stop-to-end-turn an OpenAI→Anthropic converter that maps finish reason "stop" to stop_reason: "end_turn" without checking for tool calls; Gemini ends tool-call turns with "stop", so Anthropic SDK tool runners run no tools Gemini OpenAI compatibility; found in OpenAI→Anthropic gateways
LDL012 openai-gemini-sampling a non-default temperature / top_p sent to OpenAI o-series, gpt-5, gpt-5.5 or gpt-5.6 models (400 unless gpt-5.5+ runs with reasoning effort "none"), or a temperature below 1.0 sent to a Gemini 3 model (Google warns of looping) gpt-5.5 / gpt-5.6: evidence is issue reports only, OpenAI doesn't document it (khoj#1377, openless#888); Gemini 3: Gemini 3 guide
LDL013 gemini-thoughts-tokens Gemini's candidates_token_count / candidatesTokenCount reported as the output (completion) tokens in a scope that never reads thoughts_token_count; thinking tokens are reported apart and billed as output semantic-kernel#14671, CowAgent#3850, LandPPT#143
LDL014 stop-reason-map a dict of Claude or Bedrock Converse stop reasons that leaves out ones the API returns (stop_sequence, refusal, model_context_window_exceeded, guardrail_intervened…): an error when it is indexed with [...] (KeyError), a warning when a lookup with .get just loses the reason semantic-kernel#14616, semantic-kernel#14631
LDL015 message-delta-usage an Anthropic stream handler whose message_delta branch takes output_tokens but none of the input or cache counts; message_delta usage is cumulative and, with server tools, its input and cache counts grow past message_start's (warning) agentscope#3428, posthog-python#1112, posthog-python#1074, mlflow#26908
LDL016 cache-excluded-from-input prompt_tokens, or input_tokens in OpenTelemetry GenAI code, set from Anthropic or Bedrock usage without the cached tokens, which those providers report apart (warning) opentelemetry-python-genai#1018
LDL017 openai-refusal-dropped an OpenAI chat message turned into output from .content and .tool_calls without reading .refusal; a refused request has empty content and its text only in refusal (warning) posthog-python#1095, logfire#2582
LDL018 gemini-finish-reason-map a mapping of Gemini finish reasons that treats SAFETY as a stop for content but not RECITATION, BLOCKLIST, PROHIBITED_CONTENT or SPII (warning) semantic-kernel#14632

llm-drift-lint --list-rules prints the rules in the installed version.

False positives are treated as bugs. When a rule needs to know the model and can't tell statically which one a call uses, it stays silent. LDL003 is the exception: reading content[0].text is fragile on every current Claude model, so it only stays silent when the request visibly disables thinking or the model is known not to think by default.

Does it work?

tests/corpus/ holds the real files from the upstream fixes above, as they were just before and just after each fix, plus the findings a correct linter must report. The test suite checks all of them. On 16 large open-source code bases (langchain, llama_index, crewAI, dspy, agno, langgraph, semantic-kernel, autogen and others) the six v0.1 rules report exactly two findings. Both are real bugs: AnthropicLLM in langchain-anthropic returns response.content[0].text and breaks on models that think by default (reported as langchain-ai/langchain#41263).

Install

pip install git+https://github.com/pcbeingused333/llm-drift-lint

Use

llm-drift-lint src/                       # text report, exit code 1 if anything is found
llm-drift-lint src/ --format json         # machine-readable
llm-drift-lint src/ --select LDL001,LDL004
llm-drift-lint src/ --ignore LDL006
llm-drift-lint src/ --include-tests       # test directories are skipped by default
llm-drift-lint src/ --fail-on error       # exit 0 when there are only warnings

Findings are errors, with these exceptions that are warnings: LDL007 on a model whose shutdown date is still ahead (until that day), LDL012 on a Gemini 3 temperature, which Google says degrades output rather than failing the request, LDL014 on a map looked up with .get, where a missing stop reason is lost rather than raising, LDL015, whose counts are wrong only on requests that use server tools, and LDL016–LDL018, where the code may follow a convention of its own. Warnings fail the run too unless you pass --fail-on error.

Silence one line:

client.messages.create(model=MODEL, temperature=0)  # ldl: ignore[LDL001]

or put # ldl: ignore[LDL001] alone on the line above. A bare # ldl: ignore silences every rule on that line.

In GitHub Actions

--format github emits workflow annotations, so findings show up on the PR diff:

- run: pip install git+https://github.com/pcbeingused333/llm-drift-lint
- run: llm-drift-lint src/ --format github

As a pre-commit hook

- repo: https://github.com/pcbeingused333/llm-drift-lint
  rev: v0.2.0
  hooks:
    - id: llm-drift-lint

How model knowledge is kept

What each model accepts lives in one table, src/llm_drift_lint/models.py, and every entry cites its source: provider documentation or the upstream PR that hit the problem. Rules never hard-code model names. When a provider changes behavior again, updating the linter means adding a row and a test.

Retirement dates live there too (OPENAI_SHUTDOWNS, CLAUDE_RETIREMENTS, GEMINI_SHUTDOWNS, VERTEX_GEMINI_RETIREMENTS), each with the date the provider page was read. LDL007 compares them with today's date, so the same default is reported as "shuts down on …" before the date and "shut down on …, so requests fail" after it.

License

MIT

About

Static checks for LLM API calls that break when providers change model behavior (Claude 5 drift: sampling params, thinking blocks, forced tool_choice...)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages