Sub topic 1
Start from the task, not the model
Choosing a model is easier when you first write down what your application needs. This chapter shows how to turn a vague idea ("we need a good LLM") into a short list of concrete criteria. Later chapters measure candidates against those criteria.
Prerequisites
This chapter assumes you have:
- Called an HTTP API or an SDK before, and can read a JSON response.
- Basic Python reading ability. The code here is short.
- A general idea of what a large language model (LLM) does.
- Familiarity with the terms prompt (the input text you send), token (a chunk of text the model reads or writes, often a word fragment), and context (all the tokens the model can see in one request).
Why the task comes first
A common mistake is to pick the model that tops a public leaderboard and then build around it. Leaderboards measure general ability on public benchmarks. Your application has a narrow job, specific inputs, a budget, and legal constraints. A model that is excellent overall can still be a poor fit if it is too slow, too expensive, or not allowed to see your data.
Working from the task reverses the order:
- Describe the job and what a correct result looks like.
- Turn those needs into measurable criteria.
- Find the cheapest, smallest option that meets them.
The last step reflects the guiding rule of this tutorial: pick the smallest model that meets your requirements. Larger models cost more, respond more slowly, and need more hardware if you run them yourself.
Describe the task precisely
Write the task in one or two sentences, then list the inputs and outputs. Vague descriptions hide the criteria that decide the choice.
Compare these two descriptions:
- Vague: "A chatbot for our support site."
- Precise: "Given a customer message and up to three help-center articles, write a reply under 120 words that cites an article. It must run in under 3 seconds for the first words to appear, and the message may contain account details."
The precise version reveals several things at once. The input is short, so a large context window is not needed. Speed matters. The reply format is constrained. Customer data is involved, which raises privacy questions.
From task to criteria
Each property of the task maps to a criterion you can check. The table lists the main ones. Each is covered in its own chapter later.
| Task property | Criterion it creates | Question to ask |
|---|---|---|
| How hard the reasoning is | Quality and model size | Can a small model do this, or does it need a large one? |
| How much text goes in per request | Context window | Does the longest realistic input fit with room for the answer? |
| How many requests, and how long each is | Token cost | What is the monthly spend at expected volume? |
| How fast users need a reply | Latency | How long until the first token and the full reply? |
| How many users at once | Throughput | How many requests per second must be sustained? |
| Sensitivity of the data | Privacy and compliance | May this data leave our network or region? |
| Team skills and budget | Operational effort | Who runs, patches, and monitors this? |
| Likelihood of change | Portability | How hard is it to switch models later? |
Not every criterion matters equally for every project. A nightly batch job that summarizes internal reports does not care about latency but cares a lot about cost per document. A live voice assistant is the opposite.
Separate must-haves from preferences
Sort criteria into two groups.
- Hard constraints are pass or fail. Examples: "customer data must stay in the EU", "inputs reach 60,000 tokens", "must run offline on a device". A model that fails one is out, however good it is.
- Soft goals are things you trade off. Examples: lower cost, faster replies, slightly better writing style.
Apply hard constraints first. They often shrink the candidate list sharply before you compare anything else. Then use soft goals to rank what remains.
Capture the task as data
A short, structured requirements record keeps the team honest and gives you something to revisit later. This example stores requirements in Python and checks a candidate against the hard constraints. The candidate figures are made-up placeholders for illustration.
from dataclasses import dataclass
@dataclass
class Requirements:
max_input_tokens: int
max_first_token_seconds: float
data_may_leave_network: bool
max_monthly_cost_usd: float
@dataclass
class Candidate:
name: str
context_window: int
first_token_seconds: float
runs_on_own_hardware: bool
est_monthly_cost_usd: float
def failed_constraints(req: Requirements, cand: Candidate) -> list[str]:
"""Return the hard constraints the candidate fails (empty list means it passes)."""
failures = []
if cand.context_window < req.max_input_tokens:
failures.append("context window too small")
if cand.first_token_seconds > req.max_first_token_seconds:
failures.append("too slow to first token")
if not req.data_may_leave_network and not cand.runs_on_own_hardware:
failures.append("data would leave the network")
if cand.est_monthly_cost_usd > req.max_monthly_cost_usd:
failures.append("over budget")
return failures
req = Requirements(
max_input_tokens=6_000,
max_first_token_seconds=1.5,
data_may_leave_network=False,
max_monthly_cost_usd=500.0,
)
candidates = [
Candidate("hosted-large", 200_000, 0.9, False, 320.0),
Candidate("open-small", 32_000, 0.6, True, 210.0),
]
for cand in candidates:
problems = failed_constraints(req, cand)
print(cand.name, "->", "passes" if not problems else problems)
# hosted-large -> ['data would leave the network']
# open-small -> passesThe code does not choose a model for you. It makes the elimination step explicit and repeatable. The quality criterion is missing on purpose, because you cannot read quality from a spec sheet. You measure it, and the evaluation chapter shows how.
The overall flow
The diagram shows how the pieces of this tutorial fit together. The task feeds the criteria, hard constraints filter the candidates, and measurement picks among the survivors.
Common mistakes
- Choosing by brand or hype. A familiar name is not a requirement.
- Sizing for the hardest case. If 5% of requests are hard, a large model for everything wastes money. Routing (a later chapter) can send only those to a larger model.
- Ignoring output length. Output tokens usually cost more than input tokens and take longer to produce.
- Leaving out non-functional needs such as logging, audit trails, or regional hosting. These often decide the hosted versus self-hosted question.
- Treating the choice as permanent. Models, prices, and your own needs change, so plan to revisit it.
What comes next
With a requirements record in hand, the next chapters examine the two main families of options: hosted APIs and open-weight models. Then they cover the numbers you need to compare them: model size, context window, token cost, memory, and speed.
Exercise
A team builds a tool that reads 40-page contracts (about 25,000 tokens each) and extracts the parties and dates. The contracts are confidential and must not be sent to third parties. Name one hard constraint and one soft goal, and say which should be applied first.
Show answer
Hard constraints: the model must accept at least 25,000 tokens of input plus room for the output (context window), and the contract text must not go to a third party (so a self-hosted open-weight model, or a hosted option whose terms explicitly permit this). Soft goals: lower cost per contract, or faster processing. Apply the hard constraints first, because they eliminate candidates outright. Then rank the remaining models by the soft goals and by measured accuracy on sample contracts.
Exercise
Rewrite the requirement "the assistant should answer quickly and cheaply" as two testable criteria.
Show answer
For example: "95% of requests return the first token within 1.5 seconds" and "average cost per request is under $0.005 at the expected monthly volume". Each has a number and a unit, so you can measure a candidate against it.