Choosing LLMs by Scenario: A Practical Approach to Task Matching

    Selecting the right Large Language Model (LLM) goes beyond a single trial run; it requires treating model selection as an engineering problem. This article explores how to match task requirements with model capabilities by deconstructing task types, evaluating core dimensions like context length and cost, and building a custom evaluation set. Learn how to implement model routing strategies and avoid common pitfalls to ensure a cost-effective and reliable LLM deployment.

    Why Choosing a Model is an Engineering Problem

    Many people choose Large Language Models (LLMs) based on impressions or a single experience. A smooth conversation does not mean the model suits all tasks. Model capabilities, response speed, context capacity, and usage costs vary significantly. Essentially, selection is about matching task requirements with model characteristics.

    Treating selection as an engineering problem requires answering three questions: what capabilities does the task need, which metrics can be quantified, and can the results be reproduced? Only by answering these clearly can the selection be justified.

    Deconstruct Task Types First

    Different tasks have distinct requirements for models. Common types can be categorized into five groups:

    1. Creative Writing: Requires rich language expression, style control, and structural organization. Copywriting, storytelling, and marketing scripts fall into this category.
    2. Code Development: Requires accurate requirement comprehension, executable code generation, error explanation, and modification suggestions.
    3. Long Document Processing: Requires locating information within lengthy inputs, summarizing key points, and maintaining consistency. Contracts, technical specifications, and research reports fit here.
    4. Analysis and Reasoning: Requires multi-step deduction, weighing pros and cons, and forming conclusions. Data analysis, scheme comparison, and decision support belong to this type.
    5. Daily Q&A: Short questions with high frequency, focusing on response speed and natural interaction.

    After deconstruction, each task type corresponds to a set of prioritized capability metrics.

    Core Dimensions for Model Selection

    Evaluate each dimension during selection:

    • Context Length: The input volume a model can handle at once determines whether it can process an entire document. When input exceeds the limit, common practices like segmentation or summarization increase the risk of information loss.
    • Reasoning and Coding Capabilities: Quality varies greatly in multi-step reasoning and code generation. It requires verification with real tasks rather than just relying on marketing claims.
    • Response Speed and Cost: High-frequency simple tasks should prioritize models with fast responses and low unit prices, while complex tasks should invoke more capable models.
    • Interaction Modality: Mobile voice interaction, web chat, and API calls have different requirements for latency, streaming output, and format constraints.
    • Data Compliance: When involving internal materials or personal information, confirm data storage, retention, and training usage policies, aligning with the security team.

    Build Your Own Evaluation Set

    Public benchmark scores serve only as references. Reliable conclusions come from test sets closely tied to your own business. Follow these steps:

    1. Collect 50 to 200 samples from historical tickets or real requirements, covering various tasks.
    2. Write reference answers or scoring criteria for each sample.
    3. Batch call candidate models with unified parameters (e.g., temperature, max output length).
    4. Score using automated metrics combined with manual spot checks, and record the results.

    The schematic code for the evaluation process is as follows:

    1. def evaluate(models, test_cases, scorer):
    2. """Get the average score of multiple models on the same test set."""
    3. results = {}
    4. for name, call in models.items():
    5. scores = []
    6. for case in test_cases:
    7. output = call(case["prompt"])
    8. scores.append(scorer(output, case["reference"]))
    9. results[name] = sum(scores) / len(scores)
    10. return results

    Ensure consistent testing conditions, including prompt templates, input order, and scoring criteria, otherwise the comparison is meaningless.

    Implement Selection as a Routing Strategy

    After determining the optimal model for each task type, you can implement routing at the application layer to automatically direct requests to the appropriate model.

    1. TASK_ROUTE = {
    2. "creative_writing": "general_writing_model",
    3. "code_generation": "code_model",
    4. "analysis_reasoning": "reasoning_model",
    5. "general_qa": "fast_general_model",
    6. }
    7. LONG_CONTEXT_THRESHOLD = 32_000 # Example threshold, adjust based on testing
    8. def pick_model(task_type: str, context_tokens: int) -> str:
    9. if context_tokens > LONG_CONTEXT_THRESHOLD:
    10. return "long_context_model"
    11. return TASK_ROUTE.get(task_type, "fast_general_model")

    Routing rules should be written into configurations rather than scattered in the code, making them easy to update with evaluation results. The model names in the routing table can be replaced with actual deployed model identifiers.

    Common Pitfalls

    • Relying solely on benchmark scores: Benchmark tasks may differ greatly from business scenarios; rely on your own evaluations.
    • Using a single experience to replace systematic testing: One or two conversations cannot reflect stability; analyze the distribution of multiple results.
    • Neglecting data security: Inputting sensitive materials into unevaluated services may cause leaks; confirm compliance requirements first.
    • Using one model for all tasks: General-purpose models suffice in most scenarios, but specialized selection is often more cost-effective for high-frequency coding or ultra-long documents.
    • Ignoring cost structure: Comparing only unit prices without calculating the average consumption per task can easily underestimate the total cost.

    Implementation Recommendations

    1. Sort out the team’s high-frequency tasks and list the top three to five.
    2. Build around 50 evaluation samples for each task type to complete the initial comparison.
    3. Design routing rules and keep a manual switch option.
    4. Re-test quarterly or after model version updates to update the routing table.
    5. Record the latency, cost, and user feedback of each call for subsequent optimization.

    Selection is not a one-time decision. As task structures change and models iterate, the optimal solution will also change. Establishing a re-testable evaluation mechanism is more valuable than memorizing a specific conclusion.