Model routing is an admission decision. Capability, evaluation, and data policy establish eligibility before cost or latency can influence selection.
Policy-Gated AI Model Router
Model selection begins with eligibility; cost and latency optimize only among proven-safe candidates.
const eligible = registry.models.filter(model =>
model.capabilities.hasAll(task.required)
&& model.regions.includes(task.dataRegion)
&& evals.passes(model.version, task.evaluationSet, task.minimumScore)
&& policy.allows(task.risk, model),
)
const ranked = eligible.sort((a, b) => score(a, task) - score(b, task))
for (const model of ranked) {
const reservation = await capacity.tryReserve(model, task.maximumUsage)
if (!reservation) continue
try { return await infer(model, task, { signal: deadlineSignal }) }
catch (error) { if (!isSafeFallback(error)) throw error }
finally { await capacity.settle(reservation) }
}
return deterministicFallback(task) // never route to an ineligible modelInvariant: Every selected model satisfies the task’s capability, policy, evaluation, budget, and deadline constraints.
Use when: Several models can serve a task, but quality, privacy, cost, and capacity constraints differ.
Why this boundary matters
An available substitute may lack the capability, evaluation evidence, or data policy required by the task. Blind fallback trades availability for correctness.
Failure policy
| Boundary | Action |
|---|---|
| Candidate fails capability or data policy | Remove before optimization |
| Evaluation evidence is stale | Quarantine from consequential tasks |
| Capacity and budget reserved | Execute inside the remaining deadline |
| Primary times out | Try one eligible alternate only if budget remains |
| No eligible model | Use deterministic fallback, review queue, or fail |
| Tool outcome ambiguous | Reconcile before any model or tool retry |
Trade-offs
Routing improves resilience and economics but expands the evaluation matrix and can hide provider differences. Every model, prompt, tool, and policy combination creates a versioned behavior that needs evidence.
Decision rule: Route dynamically only among configurations already approved for the exact task and risk class; never make a model eligible merely because it is available.
Further reference
Browse all engineering snippets · Read the inference-routing architecture