LLM Model Selection: An Engineering Approach to Routing and Governance
This article addresses the common engineering cycle of model selection, prompt tuning, and re-selection, and explains why the root cause is usually a single pipeline handling heterogeneous workloads rather than a weak model. It breaks LLM workloads into three families with distinct requirements, shows how to build reproducible capability profiles with fixed evaluation sets and metrics, and presents a rule-first routing layer with a fallback member. It also covers constrained decoding with validation and retry for structured output, treating the model pool as a resource pool with quotas, scheduling, and caching, and closing the loop with automated metrics, human review, and business indicators. Readers will get concrete code samples and operational practices for turning one-off model selection into a continuously optimizable process.
The pattern is common in engineering practice: a team picks one “primary model,” spends a few weeks tuning prompts, then discovers that certain tasks remain unreliable — long documents get truncated, table fields shift out of alignment, and latency spikes during batch generation. A second round of selection begins. This “select, tune, re-select” loop burns a large amount of engineering hours. The root cause is rarely that a model is not good enough; it is that heterogeneous workloads are being pushed through a single pipeline. A more sound approach is to expand the model pool and turn the selection problem into a routing and governance problem.
1. Split the Workloads First: Three Task Types, Different Capability Demands
The first type is long-context, deep-reasoning workloads, such as contract clause comparison, research report synthesis, and multi-layer causal reasoning. The key constraints are the effective context window and long-range consistency: the model must locate evidence across tens of thousands of words, keep earlier and later conclusions from contradicting each other, and produce Chinese output that reads close to human writing rather than stiff, template-like text.
The second type is structured data processing workloads, such as consolidating messy transaction records into conclusions, aligning tables with inconsistent fields, and emitting data in a fixed pattern that can be written directly to a database. The key constraints are format adherence and numeric stability. Output must be parseable by downstream programs, and the cost of a missing field or a type drift is far higher than prose that is not elegant.
The third type is low-latency, high-throughput workloads, such as batch title generation, short-video voiceover scripts, and compressing a two-hour meeting transcript into key points. The key constraints are throughput per unit time and time to first token. These tasks tolerate more error but are extremely sensitive to concurrency and cost.
Mixing all three behind one entry point inevitably produces a game of whack-a-mole: a configuration tuned for long documents makes short tasks slower and more expensive, while a configuration tuned for strict formatting sacrifices output quality on long-form reasoning.
2. Capability Profiles: Replace Subjective Impressions with Reproducible Evaluation Sets
The first step in expanding the model pool is not onboarding more models. It is building reproducible capability profiles. Maintain a small evaluation set per workload type (50–200 items each is enough) and fix the scoring criteria:
{"task_family": "structured_extraction","metrics": {"schema_valid_rate": 0.98,"field_error_rate": 0.01,"p95_latency_ms": 2600,"cost_per_1k_calls": 1.0},"sample_size": 120,"version": "2026-03-01"}
The value of a profile is turning “this model feels more stable” into comparable numbers. Re-run the same evaluation after every model pool expansion or version change to determine whether a new member fills a gap or introduces a regression.
3. Routing Layer Design: Rules First, Model Fallback
Routing does not need a complex model from day one. In most scenarios, rules cover the majority of traffic:
def route(req):if req.estimated_tokens > 30000 or req.task == "deep_analysis":return "long_context_member"if req.output_schema is not None:return "structured_member"if req.batch_size > 20 and req.max_latency_ms < 3000:return "fast_member"return "default_member"
Above the rule layer, add a lightweight classifier for boundary cases, and keep a default member as a fallback so a routing failure never turns into a hard request error. Three engineering points matter: log routing decisions to a logging service for traceability; pin retries of the same request to the same member so jitter is not amplified; and wire member health into monitoring and alerting so a member is automatically down-weighted after consecutive failures.
4. Handling Structured Output Stability
For the second workload type, prompt constraints alone are far from sufficient. A more reliable approach is “constrained decoding plus validation and retry”: constrain output to a predefined schema first, then run schema and type validation in code, retry with the error information attached on failure, and after the retry limit is exceeded, route to a human or a degraded queue.
def call_structured(payload, retries=2):for i in range(retries + 1):raw = client.generate(payload, schema=payload["schema"])ok, err = validate(raw, payload["schema"])if ok:return rawpayload["feedback"] = errreturn fallback_queue.push(payload)
It is also advisable to double-check numeric fields and to draw a clear line between what the model generates and what the program computes: anything that can be calculated should never be left to the model to guess.
5. Cost, Latency, and Capacity: Treat the Model Pool as a Resource Pool
A model pool is essentially a resource pool and needs unified quotas and priorities. Set token buckets per business line, queue long-document tasks separately so a large batch of short tasks cannot starve them, and schedule offline tasks that tolerate delay into off-peak windows. Caching is often underestimated: requests such as meeting summaries and title generation repeat heavily, and caching results against normalized inputs can significantly cut call volume. All capacity assumptions should be based on your own evaluations and load tests, not on figures claimed externally.
6. Quality Loop and Evolution Mechanism
Going live is not the finish line. Build three layers of feedback: automated metrics (format compliance rate, field error rate, latency and failure rate), sampled human review (readability, factual consistency), and business metrics (rework rate, human editing time). When a member degrades across consecutive profile evaluations, down-weight it first and then take it offline, keeping version records so you can roll back. In related practice, Baidu AI Cloud is typically placed behind a unified gateway and works with common capabilities such as object storage, message queues, container platforms, logging services, and monitoring and alerting to form an observable, rollback-capable call chain.
Conclusion
“Which model should we use” has no final answer, but “how to put each model in the right place” can be solved through engineering. Classify the workloads, quantify capabilities, codify routing rules, program the validation, and pool the capacity — selection then becomes a continuously optimizable process instead of a one-time bet. The right way to expand a model pool is not to pile up more candidates, but to make every addition correspond to a specific gap that has been clearly addressed.
