Repository navigation
refactor(types): replace Any with proven types in 6 files - #41947
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
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 8ee7591. Configure here.
TLDR
Problem this solves:
Anysilently disables type checking wherever it landsAnyerrors across the backend treeHow it solves it:
Anywith proven types in 6 filesAnyerrors, 83 basedpyright errors totalAnyUser Flow
This PR only changes type annotations in six
litellm/modules, so the Before and After flows below are identical step for step; the same live proxy calls returned the same statuses and shapes at the merge base and at the tip.Before: every call behaves the same way it does today, and the Fireworks call fails with the provider's own account precondition error that has nothing to do with this change.
POST http://litellm-domain/v1/chat/completionswithmodel: qa-geminiand a one-word prompt:HTTP 200,content='PONG',finish_reason=stop, usage with prompt and completion tokens above zero.POST http://litellm-domain/v1/chat/completionswithmodel: qa-openai,stream: trueandstream_options.include_usage:HTTP 200, a handful of SSE chunks that assemble into a short count (the model varies the wording: 8 chunks spelling4 5 6on the Before run, 11 spelling1, 2, 3.on the After run), then a final usage chunk with prompt tokens above zero.POST http://litellm-domain/v1/embeddingswithmodel: qa-embed:HTTP 200, one 3072-dimension vector,prompt_tokens=5.POST http://litellm-domain/key/generateas the master key, with access toqa-geminionly:HTTP 200, a key shaped likesk-....POST http://litellm-domain/v1/chat/completionswith that virtual key andmodel: qa-gemini:HTTP 200,content='OK'.POST http://litellm-domain/v1/chat/completionswith that virtual key and a model it may not use:HTTP 403.GET http://litellm-domain/key/info?key=sk-...as the master key: the key'sspendis greater than zero.POST http://litellm-domain/key/deleteas the master key:HTTP 200, the deleted key echoed back; reusing the deleted key on/v1/chat/completionsright away still returnedHTTP 200in this run on both legs, a two-worker key-cache timing effect noted under Caveats.GET http://litellm-domain/guardrails/listas the master key:HTTP 200,guardrails: [].GET http://litellm-domain/v1/modelsas the master key:HTTP 200,qa-embed,qa-fireworks,qa-gemini,qa-openai.POST http://litellm-domain/v1/responseswithmodel: qa-gemini, then again withstream: true:HTTP 200both times,status=completed, textPONG, and for the stream 9 events fromresponse.createdtoresponse.completed.POST http://litellm-domain/v1/chat/completionswithmodel: qa-fireworks:HTTP 412whose JSON body is anerrorobject (nochoices) carrying Fireworks' ownPRECONDITION_FAILEDmessage that the account is suspended; the gateway relays the provider error unchanged.POST http://litellm-domain/v1/chat/completionswithmodel: qa-geminiand aget_weatherJSON-schema tool:HTTP 200, one tool callget_weatherwith{"city": "Paris"},finish_reason=tool_calls.After: every call behaves exactly as before, including the Fireworks account error, because nothing at runtime changed.
POST http://litellm-domain/v1/chat/completionswithmodel: qa-geminiand a one-word prompt:HTTP 200,content='PONG',finish_reason=stop, usage with prompt and completion tokens above zero.POST http://litellm-domain/v1/chat/completionswithmodel: qa-openai,stream: trueandstream_options.include_usage:HTTP 200, a handful of SSE chunks that assemble into a short count (the model varies the wording: 8 chunks spelling4 5 6on the Before run, 11 spelling1, 2, 3.on the After run), then a final usage chunk with prompt tokens above zero.POST http://litellm-domain/v1/embeddingswithmodel: qa-embed:HTTP 200, one 3072-dimension vector,prompt_tokens=5.POST http://litellm-domain/key/generateas the master key, with access toqa-geminionly:HTTP 200, a key shaped likesk-....POST http://litellm-domain/v1/chat/completionswith that virtual key andmodel: qa-gemini:HTTP 200,content='OK'.POST http://litellm-domain/v1/chat/completionswith that virtual key and a model it may not use:HTTP 403.GET http://litellm-domain/key/info?key=sk-...as the master key: the key'sspendis greater than zero.POST http://litellm-domain/key/deleteas the master key:HTTP 200, the deleted key echoed back; reusing the deleted key on/v1/chat/completionsright away still returnedHTTP 200in this run on both legs, a two-worker key-cache timing effect noted under Caveats.GET http://litellm-domain/guardrails/listas the master key:HTTP 200,guardrails: [].GET http://litellm-domain/v1/modelsas the master key:HTTP 200,qa-embed,qa-fireworks,qa-gemini,qa-openai.POST http://litellm-domain/v1/responseswithmodel: qa-gemini, then again withstream: true:HTTP 200both times,status=completed, textPONG, and for the stream 9 events fromresponse.createdtoresponse.completed.POST http://litellm-domain/v1/chat/completionswithmodel: qa-fireworks:HTTP 412whose JSON body is anerrorobject (nochoices) carrying Fireworks' ownPRECONDITION_FAILEDmessage that the account is suspended; the gateway relays the provider error unchanged.POST http://litellm-domain/v1/chat/completionswithmodel: qa-geminiand aget_weatherJSON-schema tool:HTTP 200, one tool callget_weatherwith{"city": "Paris"},finish_reason=tool_calls.Relevant issues
Affected release
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@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
Shared setup for both runs. Same config, same payloads, same live providers, same Postgres; only the checked-out commit differs
Before (5fc510a)
Type-check count
Run basedpyright over the tree the way
scripts/type_check_gate.pydoes:Observed:
Chat completions
Send a non-streaming chat completion to
qa-gemini:Observed:
Send a streaming chat completion with usage to
qa-openai:Observed:
Send a non-streaming chat completion to
qa-fireworks:Observed:
Tool calling
Send a chat completion to
qa-geminicarrying aget_weatherfunction tool:Observed:
Responses API
Send a non-streaming responses request to
qa-gemini:Observed:
Send a non-streaming responses request to
qa-openai:Observed:
Send a streaming responses request to
qa-gemini:Observed:
Embeddings
Send an embedding request to
qa-embed:Observed:
Virtual key lifecycle, model access control and spend
Generate a key scoped to
qa-gemini, use it on both models, read its spend, delete it and reuse it:Observed:
Guardrails and model list
List the guardrails and the models:
Observed:
After (8ee7591)
Type-check count
Run basedpyright over the tree the way
scripts/type_check_gate.pydoes:Observed:
Chat completions
Send a non-streaming chat completion to
qa-gemini:Observed:
Send a streaming chat completion with usage to
qa-openai:Observed:
Send a non-streaming chat completion to
qa-fireworks:Observed:
Tool calling
Send a chat completion to
qa-geminicarrying aget_weatherfunction tool:Observed:
Responses API
Send a non-streaming responses request to
qa-gemini:Observed:
Send a non-streaming responses request to
qa-openai:Observed:
Send a streaming responses request to
qa-gemini:Observed:
Embeddings
Send an embedding request to
qa-embed:Observed:
Virtual key lifecycle, model access control and spend
Generate a key scoped to
qa-gemini, use it on both models, read its spend, delete it and reuse it:Observed:
Guardrails and model list
List the guardrails and the models:
Observed:
Type
🧹 Refactoring
Caveats (if any)
Low
HTTP 412on both legs because the Fireworks account is suspended upstream (PRECONDITION_FAILEDin the savederrorbody, so the harness's summary printer showsKeyError: 'choices'); the status and error message matched Before and After, so it is provider state and that model adds no signal to the proof.reuse-deleted-keycase depends on a two-worker key-cache race, not on this change: across three full runs it read200/401(mismatch on the unchanged base, rerun), then401/401, then200/200at the current tip, and the two legs of the run pasted here match line for line.5fc510a6fdand8ee7591fc8with Alice, GraySwan, PromptGuard and Singulr configured plus theotelcallback returned identical statuses and bodies per guarded request (400/400/500/400 against unreachable vendor endpoints) and the same 22 span names on both. Only the Bedrock AgentCoreLlmProviders.BEDROCKline is not exercised live and is the one patch line Codecov reports uncovered; the httpx client cache key it builds is byte-identical to the old string ('async_httpx_client' + LlmProviders.BEDROCK == 'async_httpx_clientbedrock').4 5 6versus 11 chunks1, 2, 3.) because the model's wording is nondeterministic; status, chunk shape and the final usage chunk match._CustomGuardrailOptions/_CustomLoggerOptionsTypedDicts (OTEL, Alice, GraySwan) declare no fields, onlytotal=False, extra_items=object, soUnpack[...]still accepts any keyword for those constructors; they name the pass-through contract without adding new checking, and only PromptGuard's names a field.ci/circleci: litellm_utils_testingis red at the tip and is not a required check; its glob (tests/litellm_utils_tests/**/test_*.py) fails the same 12 credential- and network-dependent tests (NoCredentialsError,api.groq.comunreachable) at the merge base5fc510a6fdand at the tip, and the same job is red on unrelated open PRs fix(proxy): keep request metadata out of the cost tracking failure alert #41950 and fix(proxy): keep the raw client model out of spend logs for rejections outside the router #41943.Final Attestation
Link to Devin session: https://app.devin.ai/sessions/cad698a4dd754705a42fd5cf101db571
Open in Devin Desktop: https://app.devin.ai/desktop/session/cad698a4dd754705a42fd5cf101db571?variant=devin