Understanding Model Routing Policy in OpenSmartRoute
A model routing policy defines rules and constraints for directing requests to specific models within OpenSmartRoute. It ensures requests are routed according to security, performance, and operational requirements.
This guide explains the concept of model routing policies, their role in the routing architecture, and how to implement and manage them effectively.
What is a Model Routing Policy?
A model routing policy is a set of rules that determine how requests are routed to different models or model targets. It enforces constraints such as admissibility, safety, cost limits, and capability fit, ensuring that requests are handled appropriately.
Routing policies are integral to maintaining security, resource management, and operational consistency across the system. They operate alongside other layers like signals and strategies to provide comprehensive control.
Components of a Routing Policy
A routing policy typically includes:
- Constraints: Hard rules that requests must satisfy to be routed.
- Rejection reasons: Specific conditions under which requests are rejected.
- Admissible set: The subset of models or targets eligible for routing based on current policies.
- Enforcement: How rules are applied during the routing decision process.
In OpenSmartRoute, policies are designed to be deterministic and never traded off, providing predictable routing behavior.
Implementing a Model Routing Policy
Routing policies are implemented within the policy layer of OpenSmartRoute. They depend on signals derived from requests, such as complexity, domain, or language, to evaluate admissibility.
Here is a simplified example of configuring a routing policy:
from open_smartroute.policy import RoutingPolicy
policy = RoutingPolicy()
# Add a constraint to reject requests exceeding a token limit
policy.add_constraint(lambda request: request.token_estimate < 1000, reason='Token limit exceeded')
# Define the admissible set
policy.set_admissible_targets(['modelA', 'modelB'])
This example shows how to restrict routing based on request features and predefined targets.



