LLM Model Selection: Monitoring Metrics, Risk Control, and Implementation Steps
This article outlines the practical steps and considerations for implementing large language model (LLM) selection. It covers key monitoring metrics for routing and desensitization, strategies to mitigate data leakage and code quality risks, a two-week implementation plan, and the conclusion that model selection should be driven by empirical testing data with scenario-specific routing rules.
Key Monitoring Metrics
- Desensitization interception count: Records the number of requests replaced or intercepted by desensitization rules daily. A sudden change may indicate issues with input content or rules.
- Fallback trigger rate: The proportion of fallback model invocations. A persistently high rate suggests main model instability or a need to adjust routing rules.
- Manual correction lines per 100 requests: Summarized by routing target to compare the rework costs of different models.
Failure Case: A desensitization rule once matched only 11-digit phone numbers without spaces, missing those with spaces, causing raw numbers to appear in logs. The solution is to incorporate desensitization rules into regression testing. The sample set should include various common formats, and the test must be re-run whenever rules are modified.
Data Leakage and Code Quality Risks
- Do not include secrets, tokens, database connection strings, or raw customer data in prompts. Pasted logs must be desensitized first.
- Before generated code enters the repository, it must pass compilation, unit tests, static scanning, and dependency license checks.
- Verify the dependency names and versions provided by the model one by one to ensure the packages exist and versions are available, avoiding the introduction of non-existent or vulnerable packages.
- Retain the model ID, prompt version, and output record for each request for traceability in case of issues. These records also require access control.
- Model outputs are suggestions, not conclusions. Code involving permissions, payments, or data deletion must be reviewed line-by-line by experienced developers.
Two-Week Implementation Plan
Week 1:
- Determine the calculation methodology for the four key metrics.
- Extract 20 historical tasks, five for each category.
- Write prompt templates for each scenario and set up the testing record sheet.
Week 2:
- Run each candidate model on the same set of tasks.
- Have two reviewers score independently, aggregate data, and discuss disagreements.
Subsequent Steps: Document the selection results in team documentation, agree to re-test quarterly, and keep a record of every gateway configuration change.
Conclusion: Model selection should be based on empirical testing data from the same batch of tasks. The optimal model may vary across different scenarios; routing rules should be configured separately by scenario, selecting the model with the best empirical performance for each task type.
