chore(typing): clear 1.4k basedpyright Any errors across 21 hotspot files - #36282
Conversation
…iles Typing-only pass over the 21 files with the highest reportAny and reportExplicitAny density among self-contained modules: management endpoints, guardrails, streaming internals, response transformations, MCP server, enterprise managed files, and vector store management. Whole-tree basedpyright drops from 148,648 to 146,984 errors (-1,664), with reportAny -1,111 and reportExplicitAny -296. No rule increased repo-wide and no file regressed on any rule. No cast(), type: ignore, noqa, suppression comments, or new Any annotations anywhere in the diff, and no runtime behavior changes. Budgets ratcheted by make lint-budget-update: basedpyright -1,663 across 48 rules, ruff-strict -86, type-discipline -110.
Greptile SummaryThis PR replaces broad
Confidence Score: 5/5The PR appears safe to merge, with no concrete changed-code failure identified The reviewed changes preserve current request, persistence, authorization, and streaming behavior while narrowing static types and validating previously untyped boundaries
|
| Filename | Overview |
|---|---|
| litellm/a2a_protocol/providers/pydantic_ai_agents/transformation.py | Adds structural protocols and Pydantic boundary validation while preserving the plain-dictionary request and response shapes used by current callers |
| litellm/responses/litellm_completion_transformation/transformation.py | Tightens tool-call, image, and response transformation types without an established behavioral regression |
| litellm/litellm_core_utils/streaming_chunk_builder_utils.py | Replaces broad streaming usage and delta types with precise wrappers and TypedDicts while preserving assembly logic |
| litellm/proxy/management_endpoints/model_management_endpoints.py | Refactors model persistence typing; existing model parameters and metadata remain merged and serialized as before |
| litellm/proxy/management_endpoints/ui_sso.py | Adds typed SSO and repository seams without changing session, redirect, or authentication behavior |
| litellm/proxy/_experimental/mcp_server/server.py | Introduces typed MCP session and server-state accessors that preserve existing runtime operations |
| litellm/proxy/guardrails/guardrail_endpoints.py | Narrows guardrail endpoint and logging types through identity helpers and protocols without changing CRUD behavior |
| enterprise/litellm_enterprise/proxy/hooks/managed_files.py | Adds typed Prisma table protocols and narrower managed-file interfaces while retaining the same database calls and access checks |
| basedpyright-code-budget.json | Lowers static-analysis ceilings to match the reduced diagnostic counts |
Reviews (1): Last reviewed commit: "chore(typing): clear 1.4k basedpyright A..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
bugbot run |
There was a problem hiding this comment.
✅ 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 20eb7bb. Configure here.
TLDR
Problem this solves:
How it solves it:
User Flow
Before: on litellm_internal_staging, admins manage keys, teams, models, and guardrails while developers stream completions and call the responses, messages, and MCP surfaces
POST /key/generate, a team withPOST /team/new, updates a model withPOST /model/update, and lists guardrails withGET /guardrails/list, getting the usual JSON responsesPOST /v1/chat/completionswithstream: trueand receives assembled chunks plus the final usage blockPOST /v1/responses, an Anthropic-shapePOST /v1/messages, or an MCP tool over/mcp, and an admin signs in through/sso/key/generateAfter: on this branch, every step behaves identically because the diff only changes type annotations and typed seams, no runtime code path
Relevant issues
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Whole-tree basedpyright before and after this branch, measured with the same command the CI gate runs (
uv run basedpyright --outputjson | python scripts/type_check_gate.py), counting severity=error diagnostics in-tree:No basedpyright rule increased repo-wide and no file regressed on any rule versus its baseline count.
make lint-budget-updateoutput confirming the fixes are real and the ceilings now hold them:make pre-commitis green on the staged diffType
🧹 Refactoring
Changes
Typing-only changes across the 21 files with the highest reportAny/reportExplicitAny density among self-contained modules: the key, team, model, SSO, and proxy-settings management endpoints, the guardrail endpoints plus the unified and Cisco AI Defense guardrail hooks, the streaming internals (chunk builder, responses streaming iterator, realtime streaming), the responses-to-completion and pydantic_ai transformations, Azure assistants, the Anthropic adapters handler, websearch interception, litellm_skills, the MCP server and its REST endpoints, enterprise managed files, and vector store management. No runtime behavior changes: annotations, TYPE_CHECKING imports, TypedDicts, and typed helper seams that pay the Any-to-typed crossing once per boundary
Forbidden constructs were not used anywhere in the diff: no
cast(), no# type: ignore, no# noqa, no suppression comments, no newAnyannotations. Diagnostics that could not be fixed without one of those were left in place rather than hidden, which is why roughly 1,070 target errors remain in the touched files, mostly the irreducible one-flag-per-seam residue where upstream sources likePrismaWrapper.__getattr__still return AnyBudget files are ratcheted by
make lint-budget-updateso the cleared headroom cannot silently grow back. The existing mapped suites for every touched module pass (about 4,800 tests, 0 failures caused by this diff; the only local reds fail identically on pristine litellm_internal_staging: one SSO test needing an unset GOOGLE_CLIENT_ID, the semantic tool filter file needing the optional semantic_router package, and two order-dependent MCP env var tests that only fail in a full-directory run)QA runbook
make pre-commitgreen on this branchgit diff litellm_internal_staging --statshows only typing edits plus the three budget JSONs, and no test changespython litellm/proxy/proxy_cli.py --config litellm/proxy/dev_config.yaml) and confirm clean startup, then exercise a touched surface end to end, e.g.curl http://localhost:4000/guardrails/list -H "Authorization: Bearer sk-1234"and a streamedcurl http://localhost:4000/v1/chat/completions -H "Authorization: Bearer sk-1234" -d '{"model": "gpt-5.2", "stream": true, "messages": [{"role": "user", "content": "hi"}]}'; responses are identical to litellm_internal_staging because no runtime code path changedFinal Attestation
Note
Low Risk
Changes are annotations and typed seams only; no intentional runtime behavior changes, though reviewers should watch for accidental logic edits mixed with formatting in large files like managed files and MCP server.
Overview
This PR is typing-only: it lowers basedpyright error ceilings in
basedpyright-code-budget.json(notablyreportAny/reportExplicitAny) and replaces looseAny/ untyped dict plumbing with Protocols, TypedDicts, and narrowerMapping/Sequenceannotations across several high-traffic modules.Enterprise managed files routes Prisma access through
_managed_file_table/_managed_object_tableand_ManagedFileTableActions/_ManagedObjectTableActionsprotocols so DB calls are typed at the boundary instead of flowing asAny.Streaming and adapters gain structured types in
streaming_chunk_builder_utils(chunk/usage TypedDicts,LogginginTYPE_CHECKING),realtime_streaming(client WebSocket protocol, guardrail hook typing), Pydantic AI transformation (TypeAdaptervalidation + dump protocols), Anthropic messages adapter handler (message/system type aliases, clearer proxy metadata tuple), websearch interception (AgenticLoopParams, tool sequences), and Azure assistants (OpenAIMessage.model_validate/ typed run-stream kwargs).MCP proxy surfaces tighten tool-call/logging signatures (
CallToolResult,dict[str, object]), add transport/registry protocols for stateful sessions, and type ASGI header sequences more precisely.Reviewed by Cursor Bugbot for commit 20eb7bb. Bugbot is set up for automated code reviews on this repo. Configure here.