This prompt is designed for AI infrastructure engineers operating multi-model serving systems who need to classify batch items by complexity, required capability, and latency tolerance to route them to the most cost-effective model. The core job-to-be-done is avoiding the default pattern of sending every inference request to the largest, most expensive model in your fleet. Instead, this prompt acts as a pre-processing classifier that inspects each item and produces a structured routing decision—target model, confidence score, and cost tier—before the item reaches your inference layer. The ideal user is someone managing a heterogeneous model pool (e.g., a mix of lightweight open-weight models, mid-tier fine-tuned models, and frontier models) who needs deterministic, auditable routing logic that balances quality, speed, and token budget across thousands or millions of items.
Prompt
Model Selection Routing Prompt for Cost-Optimized Batches

When to Use This Prompt
Determines when to deploy a model selection routing prompt for cost-optimized batch processing in multi-model serving systems.
Deploy this prompt when you have batch processing workloads with relaxed latency requirements—offline ETL pipelines, nightly document processing jobs, async evaluation runs, or near-real-time queues where 500ms–2s of classification overhead is acceptable. You need a defined model pool with known capability profiles and cost characteristics, plus a clear taxonomy of what 'complexity' means for your domain (e.g., reasoning depth, domain specificity, output structure requirements, context length). Do not use this prompt for sub-100ms real-time streaming where the classification step itself would violate latency SLOs; in those cases, use a lightweight heuristic classifier or pre-computed routing rules. Do not use it when you have only one model available or when all items genuinely require frontier-model quality—the prompt adds overhead without providing routing value. It is also inappropriate for workloads where routing decisions require understanding the full content of large documents or images that would need to be processed just to classify, negating the cost savings.
Before implementing this prompt, ensure you have instrumented your model pool with per-model cost tracking (tokens processed, compute time, dollar cost) and quality metrics (accuracy, factuality, task success rate) so you can validate that routing decisions actually reduce cost without degrading outcomes below acceptable thresholds. Start with a log-only deployment that records routing decisions alongside actual processing results for at least a week before enabling automated routing. This lets you measure routing accuracy, detect systematic over-routing or under-routing, and calibrate confidence thresholds before the prompt controls production traffic.
Use Case Fit
Where this prompt works and where it does not. Understand the operational boundaries before wiring it into a production pipeline.
Good Fit: Multi-Model Serving
Use when: you operate a serving layer with multiple model tiers (e.g., lightweight, standard, premium) and need to route batch items by complexity. Guardrail: Ensure each model tier has a defined capability boundary and cost profile before relying on routing decisions.
Bad Fit: Single-Model Setups
Avoid when: you only have one model available or all models share identical cost and capability profiles. Guardrail: Remove the routing step entirely; it adds latency and a potential point of failure with no cost benefit.
Required Inputs
What you need: a batch of items, each with the input payload and any available metadata (e.g., source, expected latency). Guardrail: Validate that every item has a unique identifier before routing to ensure traceability through the pipeline.
Operational Risk: Cost Overrun
What to watch: the prompt routes too many items to expensive models, blowing the token budget. Guardrail: Implement a hard cap on the percentage of items routed to premium tiers and log a warning if the cap is exceeded in any batch window.
Operational Risk: Routing Inconsistency
What to watch: identical or similar items get routed to different model tiers across batches, causing unpredictable quality and cost. Guardrail: Run a consistency eval on a golden set of items and alert if routing decisions diverge beyond an acceptable threshold.
When to Escalate
What to watch: the prompt encounters an item that doesn't fit any defined model tier or has ambiguous complexity. Guardrail: Route to a human review queue or a safe fallback model rather than guessing. Log the ambiguity for prompt improvement.
Copy-Ready Prompt Template
Paste this system prompt into your routing layer, replace placeholders, and provide batch items in the user message for cost-optimized model selection.
This prompt template is designed to be used as a system message in your model routing middleware. It instructs the routing model to classify each item in a batch by complexity, required capability, and latency tolerance, then assign it to the most cost-effective model from your catalog. The prompt enforces cost-awareness by requiring explicit reasoning about why a cheaper model is insufficient before escalating to a more expensive one. Before copying, ensure your application layer handles the input assembly: the batch items should be provided in the user message as a structured list, and the placeholders below must be replaced with your specific model catalog, cost constraints, and output schema.
textYou are a cost-aware model router for a multi-model serving system. Your task is to analyze each item in a batch and assign it to the most cost-effective model that can handle the request correctly. ## AVAILABLE MODELS [MODEL_CATALOG] ## COST CONSTRAINTS - Budget per batch: [BUDGET_PER_BATCH] - Max latency per item: [MAX_LATENCY_MS]ms - Target cost tier preference: [COST_TIER_PREFERENCE] ## ROUTING RULES 1. Default to the cheapest model that meets the item's requirements. 2. Only escalate to a more expensive model when the item explicitly requires capabilities the cheaper model lacks. 3. For each routing decision, provide a one-sentence justification explaining why the selected model is appropriate. 4. If no model in the catalog can handle an item, flag it as [UNROUTABLE_FLAG] with the reason. 5. Batch items that are simple, low-risk, or high-latency-tolerance should never be routed to premium models. ## OUTPUT FORMAT Return a JSON object with a "routing_decisions" array. Each element must follow this schema: { "item_id": "string", "selected_model": "string", "confidence": "high|medium|low", "justification": "string", "estimated_tokens": number, "fallback_model": "string|null" } ## CONSTRAINTS - Do not route items to models that lack required modalities or language support. - If an item is ambiguous, assign it to a mid-tier model and set confidence to "low". - Never exceed [MAX_LATENCY_MS]ms estimated latency for any routing decision. - Flag items containing [SENSITIVE_DATA_PATTERNS] for human review before routing.
After pasting this template, replace the square-bracket placeholders with your production values. [MODEL_CATALOG] should be a structured list of available models with their capabilities, cost per token, and latency profiles. [BUDGET_PER_BATCH] and [MAX_LATENCY_MS] should reflect your actual operational constraints. [COST_TIER_PREFERENCE] can be set to cheapest-first, balanced, or performance-first depending on your workload. [UNROUTABLE_FLAG] should be a string like UNROUTABLE that your harness can detect and escalate. [SENSITIVE_DATA_PATTERNS] should describe patterns that require human review, such as PII, credentials, or regulated data. The user message should contain the batch items as a JSON array with item_id, content, and any metadata your routing logic needs. Your application harness should parse the response, validate each routing decision against your model catalog, and log any UNROUTABLE flags or low-confidence assignments for review.
Before deploying, test this prompt with a golden dataset containing items of known complexity. Verify that simple items are consistently routed to cheaper models and that premium models are only selected when justified. Monitor for cost overruns by tracking the ratio of premium-to-budget model assignments in production. If you observe premium model usage exceeding expectations, review the justifications to identify whether the prompt is over-escalating or whether your cheap models genuinely lack required capabilities. The next section covers how to wire this prompt into an application harness with validation, retries, and cost monitoring.
Prompt Variables
Inputs the model selection routing prompt needs to work reliably. Validate these before each run to prevent cost overruns, misrouting, and silent quality degradation.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[BATCH_ITEMS] | Array of records to classify and route | [{"id": "req-1", "text": "Summarize this legal doc...", "max_latency_ms": 5000}] | Must be a non-empty array. Each item requires an id field for traceability. Reject if null or empty. |
[MODEL_CATALOG] | Available models with capabilities, cost, and latency profiles | [{"model_id": "fast-v1", "cost_per_1k_tokens": 0.001, "max_tokens": 4096, "strengths": ["summarization"]}] | Must include cost_per_1k_tokens and max_tokens for every model. Validate schema before prompt assembly. Reject if catalog is empty. |
[COST_BUDGET_TOTAL] | Maximum allowable spend for the entire batch in USD | 2.50 | Must be a positive float. Parse check required. If null, default to uncapped with a warning log. Reject negative values. |
[LATENCY_BUDGET_MS] | Per-item latency ceiling in milliseconds | 8000 | Must be a positive integer. Validate against MODEL_CATALOG latency profiles. If any item's max_latency_ms exceeds this, flag for pre-flight review. |
[QUALITY_FLOOR] | Minimum acceptable quality threshold for routing decisions | 0.85 | Float between 0.0 and 1.0. Used to prevent routing complex items to cheap, low-capability models. Reject if out of range. |
[DEFAULT_MODEL_ID] | Fallback model when no routing decision meets constraints | balanced-v2 | Must match a model_id in MODEL_CATALOG. If null, the prompt must return an explicit no-route decision instead of hallucinating a model. |
[ROUTING_RULES_OVERRIDE] | Optional explicit rules that override cost-optimization logic | [{"condition": "item.text contains 'PII'", "route_to": "private-v1"}] | If provided, each rule must have condition and route_to fields. route_to must exist in MODEL_CATALOG. Null allowed if no overrides. |
[TRACE_ID] | Batch-level identifier for logging and cost attribution | batch-2024-03-15-001 | Must be a non-empty string. Used in all log lines and cost tracking. Reject if missing or empty to prevent untraceable spend. |
Implementation Harness Notes
How to wire the routing prompt into a production batch processing pipeline with pre-processing, dispatch, cost tracking, and failure recovery.
The routing prompt is a single decision point inside a larger batch processing harness. Its job is to classify each item and return a model target and cost tier. The harness is responsible for everything around that decision: splitting batches, enriching items with context, enforcing rate limits, dispatching to the selected model, tracking actual cost against the budget, and recovering when the router or downstream model fails. Treat the prompt as a pure function that takes a pre-processed item and returns a structured routing decision. The harness owns all side effects, state, and retry logic.
A production harness typically follows this sequence: (1) Batch ingestion reads items from a queue, stream, or object store. (2) Pre-processing attaches metadata each item needs for routing—item size in tokens, client tier, latency budget, and any priority flags. (3) Routing dispatch sends each pre-processed item to the routing prompt with a strict output schema ({"model_target": "<model_id>", "cost_tier": "low|medium|high", "reasoning": "<brief>"}). (4) Validation checks that the returned model_target is in the allowed model registry and that cost_tier is a recognized value. Invalid outputs go to a dead-letter queue with the raw response and item ID. (5) Cost-aware dispatch routes the item to the selected model, recording the estimated cost tier against the item. (6) Post-execution cost tracking compares actual token usage against the tier budget and flags items that exceeded their assigned tier by more than a configurable threshold (e.g., 20%). These overruns feed back into router evaluation and threshold tuning.
Failure recovery requires clear separation between router failures and downstream model failures. If the routing prompt itself fails—timeout, malformed JSON, or model unavailability—retry with exponential backoff up to a maximum of three attempts, then fall back to a default routing rule (e.g., route to the medium-cost model with a cost_tier: medium override and log the fallback). If the downstream model fails after correct routing, the harness should retry on the same model once, then escalate to the next cost tier up if the item's priority or SLA requires completion. All routing decisions, fallback activations, and cost overruns must be logged with the item ID, timestamp, and model version for later analysis. Avoid routing prompts that carry conversational state across items—each routing call should be stateless and idempotent to keep retry behavior predictable and batch reprocessing safe.
Expected Output Contract
The routing prompt must return a valid JSON object. Use this contract to validate the response before downstream dispatch. Any field failing validation should trigger a retry or fallback to the default model.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
routing_decision | object | Top-level object must parse as valid JSON. Reject on parse failure. | |
routing_decision.model_id | string | Must match an entry in [AVAILABLE_MODELS] list. Case-sensitive exact match required. | |
routing_decision.complexity_tier | string | Must be one of: 'simple', 'moderate', 'complex'. Enum check against allowed set. | |
routing_decision.confidence | number | Float between 0.0 and 1.0 inclusive. Reject if outside bounds or non-numeric. | |
routing_decision.rationale | string | Non-empty string. Minimum 10 characters. Must reference at least one feature from [INPUT_FEATURES]. | |
routing_decision.estimated_tokens | integer | Positive integer. Must be less than or equal to [MAX_TOKEN_BUDGET] for the selected model. | |
routing_decision.fallback_model | string | If present, must match an entry in [FALLBACK_MODELS] list. Null allowed when confidence >= [CONFIDENCE_THRESHOLD]. | |
routing_decision.latency_tolerance | string | Must be one of: 'low', 'medium', 'high'. Must be consistent with the selected model's documented latency profile. |
Common Failure Modes
What breaks first when routing batches by cost and complexity, and how to prevent silent quality degradation or budget overruns.
Complexity Underestimation
What to watch: The router classifies a hard reasoning task as simple and sends it to a cheap, fast model. The output is plausible but wrong, and the error propagates downstream. Guardrail: Include a confidence score in the routing decision. Route low-confidence classifications to a human review queue or a fallback model. Log all complexity downgrades for audit.
Cost Overrun from Router Abuse
What to watch: Adversarial or poorly formed inputs trick the router into sending cheap tasks to expensive models, blowing the token budget. Guardrail: Implement a per-batch cost cap. Monitor the ratio of estimated cost to actual cost in real time. If the ratio spikes, quarantine the batch and fall back to a conservative routing policy.
Latency Budget Violation
What to watch: The router correctly identifies a complex task but ignores the latency SLA. The task is routed to a high-quality, slow model, causing a timeout for the upstream caller. Guardrail: The routing prompt must accept a max_latency_ms constraint. Validate the chosen model's p95 latency against this constraint before dispatch. Abort and re-route if violated.
Routing Inconsistency Across Batches
What to watch: Similar items in different batches get routed to different model tiers, causing unpredictable quality and cost. This erodes trust in the system. Guardrail: Use a fixed routing prompt version and temperature=0. Implement an eval that checks routing consistency on a golden set of borderline items. Alert if consistency drops below 95%.
Silent Model Deprecation
What to watch: The target model for a route is deprecated or replaced by a newer version with different behavior. The router still sends traffic, but output quality degrades silently. Guardrail: The routing harness must validate the target model ID against a live registry before dispatch. If the model is deprecated, re-route to the designated successor and log a warning.
Context Window Truncation
What to watch: A task is routed to a cheap model with a small context window. The input plus the routing prompt exceeds the limit, causing silent truncation and nonsensical output. Guardrail: Calculate the token count for the assembled prompt before dispatch. If it exceeds the target model's limit, either split the input, summarize it, or escalate to a model with a larger window.
Evaluation Rubric
Run these checks on a golden dataset of 100-500 items with known complexity and known outcomes on each model before deploying the router to production.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Routing accuracy on known items |
|
| Compare router output to golden labels on a held-out test set of 200 items |
Cost overrun detection | No batch exceeds the [COST_BUDGET] by more than 5% | Batch cost exceeds [COST_BUDGET] by > 5% without a logged override reason | Sum estimated token costs per routing decision and compare to [COST_BUDGET] across 10 representative batches |
Routing consistency | Same item routed to same model on 3 repeated runs with identical context | Model selection changes across runs for the same input without a change in [CONTEXT] or [CONSTRAINTS] | Run 50 items through the router 3 times each with temperature=0 and check for identical routing decisions |
Latency tier compliance |
| A [LATENCY_SENSITIVE] item routed to a model with p95 latency exceeding the SLA | Tag 50 items as [LATENCY_SENSITIVE] in the golden set and verify all routing decisions target models with compliant latency profiles |
Capability mismatch avoidance | Zero items requiring [REQUIRED_CAPABILITY] routed to models that lack it | An item tagged with [REQUIRED_CAPABILITY] routed to a model whose capability map does not include it | Cross-reference routing decisions against a model capability matrix for 100 capability-tagged items |
Confidence threshold gating | All items with confidence < [CONFIDENCE_THRESHOLD] escalated to fallback or human review | A low-confidence routing decision silently defaulting to the cheapest model without escalation | Inject 30 ambiguous items with known low separability and verify all trigger the escalation path |
Batch boundary handling | Zero crashes or invalid outputs when batch size is 1, [MAX_BATCH_SIZE], or empty | Router returns null, partial output, or throws an exception at edge batch sizes | Run the router with batch sizes of 0, 1, and [MAX_BATCH_SIZE] and assert valid structured output in all cases |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Start with a single-model classifier that routes between two tiers (e.g., fast and accurate). Use the base prompt with lightweight validation—skip cost tracking and latency budgets initially. Replace [MODEL_CATALOG] with a hardcoded list of 2-3 models. Run a small batch of 50-100 items and spot-check routing decisions manually.
Watch for
- Over-routing everything to the most capable model (cost explosion in production)
- Missing edge cases where complexity is ambiguous (e.g., short but nuanced inputs)
- No confidence threshold—every item gets routed somewhere without an abstention path

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us