How can AI tracing improve model routing decisions?
Summary
- Tracing improves routing by recording what each routing choice actually did: which model served the request, how long it took, how many tokens it used, whether it failed and which fallback answered instead.
- With that record you can set traffic weights, fallback order and default models from evidence, and check after every change that requests route the way you configured.
- On Databricks, Unity Gateway logs routing decisions for traffic splits and fallbacks to the
routing_informationfield ofsystem.ai_gateway.usage, with the status code, error code and latency of every attempt. - Quality is the other half of a routing decision: MLflow evaluation scores traces from each model, and Smart Routing (Beta) picks the lowest-cost model capable of each coding-agent task.
How can AI tracing improve model routing decisions?
Tracing shows what each routing choice cost and returned. For every request it records which model served it, how long it took, how many tokens it used, whether it failed and which fallback answered instead. That turns traffic weights, fallback order and default models into decisions you can check, and it tells you after every change whether requests actually route the way you configured. Routing without traces is configuration you hope works.
What is model routing?
Model routing decides which model serves a request. The common forms are weighted traffic splitting across models, fallbacks that retry a failed request on a backup model, session affinity that keeps a conversation on one model, and task-based routing that sends simpler work to a cheaper model. Each one is a bet on a tradeoff between cost, latency, quality and availability. Traces are how you settle the bet.
Routing questions that traces answer
| Routing decision | Trace signal to check |
|---|---|
| Traffic weights | Observed share of requests per destination against the configured split |
| Fallback order | Every attempt per request, with its status code, error code and latency |
| Fallback triggers | Which errors, such as rate limits or server errors, cause failover, and how often |
| Default models | Tokens, latency and error rate by destination model |
| Task-based routing | Which model handled each task, and how the result scored |
| Session affinity | Whether each session's requests stayed on one destination |
How Databricks approaches routing with tracing
Configure routing at the gateway. Unity Gateway model services support traffic splitting and fallbacks (Configure routing and fallbacks). Traffic splitting picks the primary destination for each request by weight. If that attempt fails, for example with a 429 or a server error, the gateway retries the fallback destinations in the exact order you specified, and it doesn't re-apply the split during retries. When traffic splitting is on, session affinity routes requests that share a session header to the same destination, which takes advantage of prefix caching.
Read every routing decision. Unity Gateway logs routing decisions for traffic splits and fallbacks to the routing_information field in system.ai_gateway.usage (Track model usage). It holds an attempts array with priority, action, destination, destination_id, status_code, error_code, latency_ms, start_time and end_time for each model tried. The docs include a query that checks the observed split for one model service:
SELECT
destination_name AS destination,
COUNT(*) AS request_count,
ROUND(COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (), 1) AS actual_pct
FROM system.ai_gateway.usage
WHERE
endpoint_name = 'your-endpoint-name'
AND event_time >= CURRENT_TIMESTAMP - INTERVAL 7 DAY
GROUP BY destination_name
ORDER BY actual_pct DESC;
Over time, the observed share for each destination converges to the configured percentages. Group the same table by destination_model with SUM(total_tokens), latency and status_code to compare destinations on live traffic.
Attach cost. In system.billing.usage, the usage_metadata.ai_gateway.destination_model field identifies the destination that ultimately served each request, including under traffic splitting or fallbacks (Analyze Unity Gateway cost). The cost tutorial tracks spend per token by destination model to spot regressions after a routing change (tutorial).
Trace at span level (Beta). In the unified trace table, gateway spans record databricks.action (initial_attempt or retry), databricks.destination_id, databricks.outcome and token usage. It requires the Enhanced Unity Gateway preview.
Check quality before shifting weight. Throughput and cost don't say whether answers got worse. Run mlflow.genai.evaluate() on the same evaluation dataset with each candidate model and compare the runs in MLflow before you move more traffic (Evaluate and improve).
Let the gateway pick, then audit it. Smart Routing (Beta) selects the lowest-cost model capable of handling each task for supported coding agents launched through the Unity Gateway CLI. The agent shows each subagent's selected model and, when available, the reason for the choice, and session_metadata.smart_router_name (Public Preview) groups usage by routing recipe.
FAQs
How do I confirm a traffic split is working?
Query system.ai_gateway.usage for the model service and compare the observed share per destination with your configured percentages. The gateway routes each request at random by weight, so the shares converge over time rather than matching on every request.
Do fallbacks hide failures?
Not if you read the attempts. routing_information records every model tried for a request, so a request that succeeded on a fallback still shows the failed primary attempt and its error code.
When should I change the fallback order?
When the attempts show one destination failing often with rate limits or server errors, or when a fallback answers with higher latency than you can accept. Change the order, then check the attempts again.
Is Smart Routing generally available?
No. Smart Routing is in Beta, and an account admin must enable the Enhanced Unity Gateway preview. It chooses only among system.ai model services, and users need access to every candidate model.
The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.