Repository navigation
fix(main): reject chat completions on decisions-only deployments - #51005
shadowmodder wants to merge 11 commits into
Conversation
Signed-off-by: shadowmodder <sudhirvissa@gmail.com>
|
|
||
| assert caught.value.status_code == 400 | ||
| assert route.call_count == 1 | ||
|
|
There was a problem hiding this comment.
Two things on the tests:
- AGENTS.md says to extend the mapped test file for a bug fix. The change is in
litellm/main.py, which maps totests/unit/test_main.py; this file maps tolitellm/decisions/main.py. - The guard also covers
mode: "evaluation", but no test here uses it. Parametrizing the router test over both modes would cover it.
| else None | ||
| ) | ||
| mode: object | None = info.get("mode") if info is not None else None | ||
| if not isinstance(mode, str) or not is_decisions_model_mode(mode): |
There was a problem hiding this comment.
This only looks at the deployment's model_info.mode. The Decisions code falls back to the catalog mode when the deployment has none (catalog_mode in litellm/llms/base_llm/decisions/transformation.py), and the cost map lists models with mode decisions or evaluation. Should a direct call to one of those without model_info also be rejected, or is that out of scope here?
| if model is None: | ||
| raise ValueError("model param not passed in.") | ||
| caller_kwargs: Final = cast("Mapping[str, object]", {**kwargs}) # cast-ok: completion takes untyped kwargs | ||
| _reject_decisions_only_chat_completion(model, caller_kwargs) |
There was a problem hiding this comment.
| _reject_decisions_only_chat_completion(model, caller_kwargs) | |
| _reject_decisions_only_chat_completion(model, caller_kwargs.get("model_info")) |
| model_info: object | None = request_kwargs.get("model_info") | ||
| info: Mapping[str, object] | None = ( | ||
| cast(Mapping[str, object], model_info) # cast-ok: isinstance narrows to a bare Mapping | ||
| if isinstance(model_info, Mapping) | ||
| else None | ||
| ) | ||
| mode: object | None = info.get("mode") if info is not None else None |
There was a problem hiding this comment.
These three assignments are not Final, so scripts/check_type_discipline.py litellm/main.py goes from 525 to 528 LIT010 findings, and AGENTS.md says a rule's count may not grow. as_str_mapping is already imported in this file and does the same narrowing without a cast:
| model_info: object | None = request_kwargs.get("model_info") | |
| info: Mapping[str, object] | None = ( | |
| cast(Mapping[str, object], model_info) # cast-ok: isinstance narrows to a bare Mapping | |
| if isinstance(model_info, Mapping) | |
| else None | |
| ) | |
| mode: object | None = info.get("mode") if info is not None else None | |
| info: Final = as_str_mapping(model_info) | |
| mode: Final = None if info is None else info.get("mode") |
| return response | ||
|
|
||
|
|
||
| def _reject_decisions_only_chat_completion(model: str, request_kwargs: Mapping[str, object]) -> None: |
There was a problem hiding this comment.
Taking model_info directly keeps the helper independent of the kwargs dict (goes with the other suggestions in this file).
| def _reject_decisions_only_chat_completion(model: str, request_kwargs: Mapping[str, object]) -> None: | |
| def _reject_decisions_only_chat_completion(model: str, model_info: object) -> None: |
| ### VALIDATE Request ### | ||
| if model is None: | ||
| raise ValueError("model param not passed in.") | ||
| caller_kwargs: Final = cast("Mapping[str, object]", {**kwargs}) # cast-ok: completion takes untyped kwargs |
There was a problem hiding this comment.
This new local ends up in args = _locals_snapshot(locals()) a few lines below, so it is passed on by completion_with_fallbacks(**args) and batch_completion_models(deployments=deployments, **args).
On this branch litellm.completion(model=..., messages=..., fallbacks=[...]) calls litellm.acompletion with an extra caller_kwargs={...} argument that holds a copy of every kwarg (including any credentials passed as kwargs and litellm_logging_obj). On main it does not. From reading add_provider_specific_params_to_optional_params, an unknown kwarg like this is copied into extra_body for OpenAI-SDK providers.
Reading model_info straight from kwargs avoids the new local:
| caller_kwargs: Final = cast("Mapping[str, object]", {**kwargs}) # cast-ok: completion takes untyped kwargs | |
| _reject_decisions_only_chat_completion(model, kwargs.get("model_info")) |
|
Thanks for picking this up. The guard does what the issue asks for the chat path: the router passes Requested changes are inline. The main one is the A few things outside the diff:
|
Signed-off-by: shadowmodder <sudhirvissa@gmail.com>
…eview Signed-off-by: shadowmodder <sudhirvissa@gmail.com>
|
Thanks for the careful review, @mmRoshani — all six points are addressed in the latest commits (1a86a50, cfb6c5c):
Happy to adjust further if any of this still looks off. |
|
Thanks for the quick turnaround, @shadowmodder. I went through Confirmed fixed
One blocker in That commit deletes all of This restores it, and the file then drops out of the PR's diff: Still open
Also
Optional
|
… mistake Signed-off-by: Sudhir Vissa <sudhirvissa@gmail.com>
…s test Signed-off-by: shadowmodder <sudhirvissa@gmail.com>
Signed-off-by: Sudhir Vissa <sudhirvissa@gmail.com>
…chat-rejection' into shadowmodder/fix/decisions-only-chat-rejection Signed-off-by: Sudhir Vissa <sudhirvissa@gmail.com>
|
Thanks for the re-review, @mmRoshani — and for catching the test-file deletion. That one was my mistake: the commit that moved the tests out deleted all of tests/unit/decisions/test_main.py instead of only the tests this PR added. Fixed now:
The guard tests pass locally on the restored tree. Happy to adjust further if anything still looks off. |
…hat reaches it Signed-off-by: Sudhir Vissa <sudhirvissa@gmail.com>
|
Three follow-ups, @mmRoshani. 08c1d3b makes the 400 text route-neutral, since /v1/completions and /v1/responses reach the same guard. I left the stricter fallback assertion out because on current main completion() already forwards a requested_tool_choice local, so it fails for a reason outside this PR. And yes please on the live proxy run, thank you. |
|
Thanks @shadowmodder, I went through the latest commits up to Confirmed
How I checked I reviewed the diff, ran the repo's lint scripts, and exercised the guard in isolation. I have not run the pytest suite locally, so I'm relying on CI for the new tests. One correction from my side Please ignore my optional suggestion about asserting that every forwarded key is a parameter of Still open
Once the required checks are green this looks good to me. |
|
Thanks @mmRoshani — on catalog models: that is intentionally out of scope, and it is already stated in the Caveats section of the description (guard keys off deployment model_info; a bare catalog name carries no deployment context). Appreciate the re-review. |
|
Merged main to clear the conflict in tests/unit/test_main.py. Main had added its own tests at the same spot, so both sets are kept and nothing in the fix itself changed. |
Part of #50876
TLDR
Problem: a hosted_vllm deployment with model_info.mode: decisions (Decision 3.0 / System One, serves /v1/systemone only) is accepted on /v1/chat/completions. LiteLLM forwards to upstream, vLLM has no such route, and the proxy returns an opaque litellm.NotFoundError: Hosted_vllmException - {"detail":"Not Found"}.
Fix: fail fast with a clear 400 before the upstream call when the target deployment's model_info.mode is decisions/evaluation.
Tests
Caveats