Skip to content

fix(auto-router): omit Claude Code system text from classifier - #40655

Merged
tin-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_classifier_drop_caller_system
Sep 11, 2026
Merged

tin-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_classifier_drop_caller_system

Conversation

@tin-berri

@tin-berri tin-berri commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Claude Code harness text dominated classifier input
  • Per-turn system reminders changed unrelated routing context

How it solves it:

  • Omit system text only for recognized Claude Code requests
  • Keep current asks and bounded conversation context unchanged

User Flow

Before: a developer sends a small Claude Code task, but harness instructions dominate the classifier input

  1. They send POST http://127.0.0.1:4488/v1/messages through Claude Code 2.1.268 with model claude-opus-5
  2. The first-turn classifier receives 2,478 input tokens for a 38-character ask
  3. Environment, agent, and skill catalogs make up 7,613 classifier-payload characters
  4. The routed model still receives the original system text

After: the same Claude Code task is classified from task-bearing conversation text

  1. They send the same POST http://127.0.0.1:4488/v1/messages through Claude Code 2.1.268
  2. The first-turn classifier receives 524 input tokens for the same ask
  3. Its user payload contains only the current ask; later turns retain bounded prior context and trajectory
  4. The routed model still receives the original system text

Relevant issues

Linear ticket

Resolves LIT-7491

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review

Screenshots / Proof of Fix

Same commands in fresh HOME directories against each revision:

ANTHROPIC_BASE_URL=http://127.0.0.1:4488 \
ANTHROPIC_AUTH_TOKEN="$RIG_KEY" ANTHROPIC_MODEL=claude-opus-5 \
ANTHROPIC_SMALL_FAST_MODEL=claude-haiku-4-5 \
claude -p 'Explain binary search in one sentence.' --output-format json
# Keep that environment and HOME for both continuation commands
claude -p --continue 'Now give one concrete example.' --output-format json
claude -p --continue \
  'Use the explainer subagent to explain binary search in one sentence. Delegate exactly that task, then relay its answer.' \
  --agents '{"explainer":{"description":"Answers a delegated explanation task","prompt":"Answer the delegated task concisely.","model":"opus"}}' \
  --allowedTools Agent --output-format json

Shared setup: a Postgres-backed proxy used a real Haiku 4.5 classifier and real Claude tier models through the sandbox gateway. Claude Code 2.1.268 ran a three-turn session with one delegated subagent. A capture proxy recorded the classifier and routed-model requests without modifying them

Before (8a4fae0e17)

  1. Run claude -p 'Explain binary search in one sentence.' --output-format json, then continue twice; the third turn delegates the same task to an explainer subagent
  2. The first classifier payload is 7,675 characters and costs 2,478 input tokens
  3. It contains # Environment, Available agent types, the skill catalog, and <total_tokens>
  4. The second classifier call quotes the <total_tokens> system reminder but retains the prior user turn
  5. The routed request contains the original user and system messages

After (63ef777454)

  1. Run the same three Claude Code turns against the fixed proxy
  2. The first classifier payload is 62 characters and costs 524 input tokens
  3. None of six classifier calls contain environment, agent, skill, or token-budget system text
  4. Later classifier calls still contain the prior user turns and Conversation so far trajectory
  5. The main and delegated routed requests retain their original user and system messages
  6. Additional Chat Completions, Responses, and Messages probes return 200; Claude Code controls omit extracted system text, while generic-client controls retain it. Native Anthropic top-level system stays outside classifier input on both revisions

Type

Bug fix, regression tests, and documentation

Caveats

Severe

  • Claude Code system-only constraints no longer guide tier selection

Medium

  • Proxies stripping the client User-Agent retain generic classification behavior
  • The browser routing preview has no client identity field

Verification

  • 1,170 tests passed across classifier and routing-preview suites
  • Eight focused regression cases passed on the final fixtures
  • Four deliberate gate mutations were caught; restored control passed
  • make check and all four delta gates passed locally
  • Greptile scored final SHA 5/5; its two findings were withdrawn
  • Prior-turn and operator-rubric behavior remain unchanged

Final Attestation

  • Regression tests cover the reproduced client shapes and generic controls

🤖 Generated with Claude Code

@tin-berri
tin-berri requested a review from a team September 11, 2026 01:33
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with a score and why that score?

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Score: 4/5

I found no blocking correctness issue. The change is narrowly scoped to classifier input: complexity_router.py:2030 detects recognized Claude Code user agents across the supported metadata locations, omits only the classifier’s caller system prompt, and leaves the original request/messages untouched for the routed completion. Generic clients still retain system context, while prior-turn and trajectory context remain enabled.

The tests provide good coverage for metadata placement, encrypted tasks, first-turn requests with context disabled, generic-client behavior, and near-match user agents. The existing Buildkite status is also successful.

I’m giving 4 rather than 5 because the behavior intentionally removes task constraints that exist only in Claude Code system text, and the browser routing preview cannot reproduce the client-identity path. Both limitations are documented in litellm/router_strategy/complexity_router/README.md:458 and the PR description, so they are understood trade-offs rather than blockers.

@codspeed

codspeed Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_classifier_drop_caller_system (63ef777) with litellm_internal_staging (a13c278)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR removes caller system text from LLM-classifier input when request metadata identifies Claude Code, while preserving conversation context and the routed request

  • Adds Claude Code detection to classifier payload construction
  • Documents the changed classifier-context behavior and configuration semantics
  • Adds regression coverage for Claude Code, generic clients, first turns, later turns, and encrypted tasks
  • Leaves no compatibility switch for operators who need system-only constraints considered

Confidence Score: 4/5

The PR should not merge until Claude Code system-context omission is configurable and the provider-specific branch is moved behind the provider boundary

Recognized Claude Code requests always lose system-only classification constraints, which can select an incapable tier and changes existing behavior without an operator-controlled compatibility path

Files Needing Attention: litellm/router_strategy/complexity_router/complexity_router.py

Important Files Changed

Filename Overview
litellm/router_strategy/complexity_router/complexity_router.py Adds unconditional Claude Code system-context omission and introduces provider-specific branching in the generic router strategy
litellm/router_strategy/complexity_router/config.py Updates classifier-context descriptions to document the new exception but exposes no compatibility override
tests/test_litellm/router_strategy/test_complexity_router.py Adds focused mocked regression coverage for recognized and generic clients without weakening existing tests
litellm/router_strategy/complexity_router/README.md Accurately documents classifier-only omission, preserved routed system text, and the system-only constraint caveat

Reviews (1): Last reviewed commit: "fix(auto-router): omit Claude Code syste..." | Re-trigger Greptile

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@codecov

codecov Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Co-Authored-By: Claude Code <noreply@anthropic.com>
@tin-berri
tin-berri force-pushed the litellm_classifier_drop_caller_system branch from 81f7890 to 63ef777 Compare September 11, 2026 01:50
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai both findings are withdrawn; final SHA adds precise system and trajectory assertions. Can you reply here with a score and why that score?

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Score: 5/5.

The final SHA addresses the withdrawn findings with precise regression coverage: recognized claude-cli/ and claude-code/ agents omit caller system text only from the classifier, generic clients retain it, and mixed metadata is handled conservatively. The assertions also verify that prior user/assistant context and the trajectory signal remain present, the current ask is unchanged, Claude Code first-turn payloads contain only task-bearing text, and neither messages nor request kwargs are mutated. The implementation preserves the original system text for the routed completion, so the behavior is scoped correctly.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 63ef777. Configure here.

@tin-berri
tin-berri enabled auto-merge (squash) September 11, 2026 02:07
@tin-berri
tin-berri merged commit 7419a53 into litellm_internal_staging Sep 11, 2026
87 of 88 checks passed
@tin-berri
tin-berri deleted the litellm_classifier_drop_caller_system branch September 11, 2026 02:18
devin-ai-integration Bot added a commit that referenced this pull request Sep 11, 2026
…nged in #40655

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
yucheng-berri added a commit that referenced this pull request Sep 11, 2026
…tion and emit tool output tokens (#40666)

* fix(datadog_llm_obs): keep tool call and result structure under redaction and emit tool output tokens

Under datadog_llm_observability_params.turn_off_message_logging the span kept only one role plus "redacted-by-litellm" per message, so Datadog showed Tool Call 0, Tool Result 0 and no tool output token data. The shared CustomLogger hook collapsed the messages before the callback ran, and the Datadog redaction then dropped tool_calls and tool_results.

The Datadog callback now opts out of the shared message collapse (redacts_messages_itself) and redacts its own normalized messages, keeping roles, tool names, ids and types while replacing content, arguments and results. Tool result tokens are counted with litellm.token_counter before redaction and shipped as the tool_output_tokens metric. Other callbacks keep the inherited behavior.

Resolves LIT-7545

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(datadog_llm_obs): drop explanatory docstrings from the redaction change

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* chore(ui): regenerate schema.d.ts for the classifier descriptions changed in #40655

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: yucheng <yucheng@berri.ai>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants