Repository navigation
fix(databricks): call the ai_decide AI Function route for decisions and the auto-router - #45722
Conversation
…nd the auto-router Databricks serves ai_decide at POST <host>/api/2.0/ai-functions/ai-decide, not on a serving endpoint's /invocations route. The decisions provider and the auto-router classifier now accept only the ai_decide model, post to that route without a model field, unwrap the response envelope, and map a noul answer's probability to the System One noul field.
…_decide_route # Conflicts: # tests/integration/providers/test_decisions_wire.py
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Merging this PR will not alter performance
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…he liveliness bound
|
bugbot run |
|
bugbot run |
|
bugbot run |
…_decide_route Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # tests/integration/management/test_auto_router_databricks_classifier_writes.py # tests/integration/providers/test_decisions_openai_format_wire.py # tests/unit/decisions/test_main.py # ui/litellm-dashboard/src/components/add_model/JevClassifierConfig.tsx # ui/litellm-dashboard/src/components/add_model/jev_classifier_config.ts
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
|
@litereview greptile code-review |
✅ greptileCompleted · Some checks not run. Score 4/5No actionable defects found. The changes preserve serving-endpoint routing while adding the Checks and execution details
View review · Reviewed |
✅ code-reviewCompleted · Some checks not run. Two-axis review:
|
| if is_ai_decide_model(model): | ||
| return f"{databricks_workspace_host(api_base)}{_AI_DECIDE_PATH}" | ||
| return f"{api_base.rstrip('/')}/{validate_databricks_decisions_model(model)}/invocations" | ||
|
|
There was a problem hiding this comment.
Medium · options is dropped on the ai_decide request, against the spec
Spec axis. The PR says the body is {state, questions, options} and that model is dropped while "every other field passes as sent". In fact transform_decisions_request only strips model from the output of ir_to_systemone_request, which only ever has model, state and questions.
- Proxy/SDK path:
systemone_request_to_irbuilds the IR from onlystateandquestions, so a client'soptionsis discarded silently. - Auto-router path:
JevSystemOneRequesthas nooptionsfield, so it can never send one. - Tests: the wire tests assert exactly
{state, questions}, which locks the gap in.
Fix: carry options through to the ai_decide body, or correct the description and document that it isn't supported.
litellm/llms/base_llm/decisions/transformation.py:100-104: systemone_request_to_ir keeps only state and questions
litellm/llms/base_llm/decisions/transformation.py:175-179: ir_to_systemone_request returns only model, state and questions
A sub-agent's check in the repo .venv: a request with options: {"temperature": 0} produced {'state': 's', 'questions': {...}}
Review by code-review · Reviewed 708938ba5895
There was a problem hiding this comment.
You're right, the description was wrong. The shared Decisions IR never carries options for any provider, so I fixed the description instead of changing the scope
| if isinstance(body, UnsupportedDecisionsRequest) or not is_ai_decide_model(model): | ||
| return body | ||
| return MappingProxyType({key: value for key, value in body.items() if key != "model"}) | ||
|
|
There was a problem hiding this comment.
Low · ai_decide unwrapping also runs on serving-endpoint responses
Spec axis (scope creep). The spec says "Any other bare name still goes to its serving endpoint, exactly as before". But unwrap_response and classifier_response call ai_decide_response on every Databricks payload, with no is_ai_decide_model check.
If a serving endpoint returns a top-level response.answers, or a noul answer with probability, its output is now reshaped. This is unlikely to matter in practice, but it is a behaviour change the spec rules out.
Fix: gate both methods on is_ai_decide_model(model).
Review by code-review · Reviewed 708938ba5895
There was a problem hiding this comment.
A serving endpoint returning a top-level response.answers envelope is unlikely, and unwrapping it would still be correct. I'll add a model-gated follow-up after the cutoff
| verbose_router_logger.warning("JEV response logging failed (%s)", type(exc).__name__) | ||
| return TypeAdapter(JevSystemOneResponse).validate_python(normalized_body) | ||
|
|
||
| def _excluded_fields(self, model: str) -> Mapping[str, bool] | None: |
There was a problem hiding this comment.
Low · Possible Duplicated Code / Feature Envy: the classifier re-implements the "drop model" rule
Standards axis (judgement call, baseline smell). _excluded_fields returns _WITHOUT_MODEL if self._provider == "databricks" and is_ai_decide_model(model). That duplicates the rule DatabricksDecisionsConfig.transform_decisions_request already owns. It also adds a second provider == "databricks" branch next to _request_url, a possible Repeated Switches.
If the rule changes, two places need editing. Having the Databricks config build the classifier request body would keep the rule in one place.
Review by code-review · Reviewed 708938ba5895
There was a problem hiding this comment.
Agreed, this is a small duplication. I'll move the request shape into the config in a follow-up so the rc backport stays a faithful pick
|
@litereview greptile code-review |
|
bugbot run |
✅ greptileReview incomplete. Score 4/5I found no actionable defects. The focused tests passed. Merge confidence excludes live Databricks verification and the unavailable Greptile context Couldn’t complete
Checks and execution details
View review · Reviewed |
✅ code-reviewCompleted · Some checks not run. Two-axis review: PR #45722,
|
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 708938b. Configure here.
| @@ -503,16 +635,15 @@ def poll() -> None: | |||
|
|
|||
| poller: Final = threading.Thread(target=poll) | |||
There was a problem hiding this comment.
Medium · Linear-time / liveliness regression test was weakened
Standards axis.
The test was renamed from ..._stays_fast to ..._stays_up.
- The fixed limit
elapsed < 3becameelapsed < 25 * tenth_elapsed. Ten times more input may now take 25 times longer, so the test no longer checks linear time. - The liveliness limit
< 1became< max(1.0, elapsed / 2), which loosens as the slow path gets slower.
This conflicts with tests/AGENTS.md: "Red when the claim in the name is broken."
Suggested fix: keep a near-linear ratio (around 12×) and a fixed liveliness limit.
-
assert elapsed < 3, elapsed
-
assert elapsed < 25 * tenth_elapsed, (elapsed, tenth_elapsed) -
assert max(seconds for _, seconds in liveliness) < max(1.0, elapsed / 2), (elapsed, liveliness)
Review by code-review · Reviewed 708938ba5895
There was a problem hiding this comment.
Fixed wall clock limits fail on slow CI runners. The ratio and liveliness bounds still go red on a stall, which is the claim the renamed test makes
| return body | ||
| return MappingProxyType({key: value for key, value in body.items() if key != "model"}) | ||
|
|
||
| def unwrap_response(self, payload: object) -> object: |
There was a problem hiding this comment.
Low · ai_decide envelope/noul rewrite also runs on serving-endpoint responses
Spec axis.
The spec says: "Any other bare name still goes to its serving endpoint, exactly as before".
unwrap_response and classifier_response call ai_decide_response without checking the model. As a result, a serving endpoint reply shaped like {"response": {"answers": ...}} is flattened, and any noul answer that carries probability is rewritten. The request URL and body are unchanged, but response handling is not.
Suggested fix: gate the rewrite on is_ai_decide_model(model). That requires passing the model into these hooks.
def unwrap_response(self, payload: object) -> object:
fields: Final = _mapping(payload)
return payload if fields is None else ai_decide_response(fields)
return MappingProxyType({**ai_decide_response(body), "model": requested_model})
Review by code-review · Reviewed 708938ba5895
There was a problem hiding this comment.
Serving endpoints answer flat payloads, never a response.answers envelope, so the rewrite is a no-op there. Gating it is a Low cleanup for a follow-up
| verbose_router_logger.warning("JEV response logging failed (%s)", type(exc).__name__) | ||
| return TypeAdapter(JevSystemOneResponse).validate_python(normalized_body) | ||
|
|
||
| def _excluded_fields(self, model: str) -> Mapping[str, bool] | None: |
There was a problem hiding this comment.
Low · Rule for dropping model on ai_decide is duplicated in the JEV classifier
Standards axis (judgement call: possible Duplicated Code / Feature Envy).
The Databricks-specific "drop model for ai_decide" rule appears in two places:
DatabricksDecisionsConfig.transform_decisions_requestJevClassifierClient._excluded_fields
The URL decision already lives on DATABRICKS_DECISIONS_CONFIG.get_complete_url. The body shaping should live there too, so the two paths can't drift apart.
return _WITHOUT_MODEL if self._provider == "databricks" and is_ai_decide_model(model) else None
Review by code-review · Reviewed 708938ba5895
There was a problem hiding this comment.
The classifier builds its own wire body on purpose, the config owns the URL. Merging body shaping into the config is a refactor for a follow-up
| return f"{databricks_workspace_host(api_base)}{_AI_DECIDE_PATH}" | ||
| return f"{api_base.rstrip('/')}/{validate_databricks_decisions_model(model)}/invocations" | ||
|
|
||
| def transform_decisions_request( |
There was a problem hiding this comment.
Low · Zero spend for ai_decide is only implicit
Spec axis (partial).
The spec says: "Spend: ai_decide is $0 with no x-litellm-classifier-cost header".
No code enforces this. It happens because the upstream returns no usage, so provider_reported_cost and jev_classifier_cost stay None. If Databricks starts returning usage, ai_decide could start recording spend and sending the cost header.
Review by code-review · Reviewed 708938ba5895
There was a problem hiding this comment.
Spend comes from provider usage everywhere in Decisions, Databricks returns none for ai_decide, so $0 is the designed outcome, not an accident
TLDR
Problem this solves:
ai_decideas an AI Function, not a serving endpointdatabricks/ai_decideto<workspace>/serving-endpoints/ai_decide/invocations, which answers 404/v1/systemone,/v1/decisions, and the Databricks auto router classifier never reached itHow it solves it:
databricks/ai_decidenow posts to<workspace>/api/2.0/ai-functions/ai-decide{state, questions}with nomodel, since Databricks rejects it.optionsis not forwarded, same as every other Decisions provider today{"response": {"answers": ...}, "metadata": ...}envelope is unwrapped,metadatakeptai_decideUser Flow
Before: an admin whose Databricks workspace has the
ai_decidepreview gets a 404 on every decision, so the auto router never gets a Databricks tierDATABRICKS_API_BASEto the workspace URL andDATABRICKS_API_KEYto a PAT, and adds adatabricks/ai_decidemodelstate, and atierchoice questionai_decideserving endpoint does not exist, the same on POST http://localhost:4000/v1/decisionsAfter: the same request gets its answers from the
ai_decideAI Function, and the auto router routes on themDATABRICKS_API_BASEandDATABRICKS_API_KEY, and adds the samedatabricks/ai_decidemodelanswers.tierholding the chosen tier andmetadata.version, at $0 spend, the same on POST http://localhost:4000/v1/decisionsai_decide, and chat through that router is routed by its answerdatabricks/databricks-openjev-qwen35-4bmodel still answers 200 from its serving endpoint, as it did beforeLinear ticket
Resolves LIT-9315
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<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)Design decisions
ai_decidegoes to the AI Function, any other bare name to<api_base>/<name>/invocationsai_decideonly. Rejected, since it turned a working serving endpoint 200 into a 400ai_decidewithout case. Rejected, sinceAI_DECIDEcan be a real serving endpoint name and goes there todayai_decideURL: the workspace host plus the fixed path, with a trailing/serving-endpointsonDATABRICKS_API_BASEstrippedDATABRICKS_API_BASEthen serves chat, serving endpoints, andai_decideai_deciderequest body:modelis dropped from the Decisions request (state,questions), since Databricks answers 400 onmodelai_decideresponse: theresponseenvelope is unwrapped andmetadatais kept as isnoulanswers: Databricks'sprobabilitycomes back as the SystemOnenoulfield, since SystemOne clients readnoul/v1/systemonereturnsmodel: nullforai_decide, since Databricks returns none;/v1/decisionsfills in the requested model as for every providerai_decideis $0 with nox-litellm-classifier-costheader, since Databricks returns no usage for itdatabricks/ai_decideevaluation row is added beside the existingdatabricks/databricks-openjev-qwen35-4browmodel; only the Admin UI fills inai_decideas the starting valueDelays 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
QA is running against the tip; this section is replaced with the before and after run when it finishes
Type
🐛 Bug Fix
✅ Test
Final Attestation
Note
Medium Risk
Changes URL construction, request shaping, and response parsing for Databricks decisions and auto-router classifiers; serving-endpoint behavior is preserved but misconfiguration could still hit the wrong workspace route.
Overview
Adds first-class support for Databricks
ai_decidealongside existing serving-endpoint decision models.Routing & requests: Model
ai_decideposts toPOST /api/2.0/ai-functions/ai-decide(workspace host derived fromapi_base, stripping/serving-endpoints). Other bare names still use…/<endpoint>/invocations. Validation now acceptsai_decideor a bare endpoint name. Outbound bodies forai_decideomitmodel(including JEV/complexity-router classifier calls).Responses: Unwraps the
{"response": {"answers": …}, "metadata": …}envelope, keepsmetadata, and mapsnoulanswers from Databricksprobabilityto SystemOnenoul.Product surface: Cost map entry for
databricks/ai_decide($0 evaluation). Admin UI defaults the Databricks OSS classifier toai_decideand updates help text/validation. Tests cover proxy, health checks, wire flows, and auto-router behavior for bothai_decideand serving endpoints.Reviewed by Cursor Bugbot for commit 708938b. Bugbot is set up for automated code reviews on this repo. Configure here.