Sub topic 19
Scoping your first LLM project
This chapter assumes you have read the earlier chapters on application patterns, prompting, evaluation, and the cost and safety trade-offs. It pulls them into one decision process. You should be comfortable with Python, JSON, and calling a model API.
Why scoping matters more for LLM projects
A first LLM project usually fails for one of three reasons: the goal is too large, nobody defined what "good" means, or a constraint such as privacy or cost surfaced after the build. A prototype can look impressive in a day. The remaining work is making it reliable, measurable, and affordable.
Scoping means deciding four things before you write much code:
- Which application pattern fits the problem.
- How you will measure success.
- What the smallest useful version is.
- Which constraints can rule the project out.
Step 1: Pick the simplest pattern that works
Start from the user's task, not from the technology. Then choose the least complex pattern that covers it. Complexity grows roughly in this order: a single prompt, structured output, retrieval, tool calls, an agent loop.
| Need | Likely pattern | Main risk |
|---|---|---|
| Shorten, rewrite, or translate text | One prompt | Dropped or altered facts |
| Sort tickets, pull fields from documents | Classification or extraction with validation | Wrong labels, malformed output |
| Answer questions from your documents | Retrieval-augmented generation | Retrieving the wrong passages |
| Look up live data or take actions | Tool calling | Wrong or unsafe calls |
| Multi-step goals with open-ended paths | Agent | Compounding errors, cost, loops |
Most first projects belong in the first three rows. An agent is rarely the right first step. If a fixed sequence of two or three prompts solves the task, write that sequence in ordinary code. It is easier to test and debug than a model choosing its own steps.
Step 2: Define success before building
Write down what a correct output looks like and collect examples. Twenty to fifty real inputs with the answers you expect is enough to start. Take them from real data, not from inputs you invented to flatter the prompt.
Choose a metric that matches the task:
- Classification: accuracy per label, plus a count of how often the fallback label is used.
- Extraction: field-level exact match, plus the rate of outputs that fail validation.
- Question answering: whether the answer is correct and whether it is supported by the retrieved text.
- Drafting and summarization: a rubric scored by a person, such as "keeps all figures" and "under 100 words".
Also set a threshold. "Route 90% of tickets correctly, and send the rest to a person" is a goal you can test. "Make support better" is not.
Step 3: Check the constraints that can end the project
Run these checks early. They are cheap to do on paper and expensive to discover late.
- Data. Can this data be sent to an external provider? Does it contain personal or regulated information? If it does, you may need a provider agreement, redaction, or a self-hosted model.
- Cost. Estimate monthly spend from request volume and token counts.
- Latency. Does the user wait for the reply? A multi-step chain adds the latency of every call.
- Error cost. What happens when the model is wrong? A bad summary is a nuisance. A wrong refund is a loss.
- Untrusted input. Will the model read text written by outsiders, such as emails or web pages? If so, plan for prompt injection, and keep the model's permissions narrow.
A back-of-envelope cost estimate takes a few lines. The prices below are placeholders, so substitute your provider's current rates.
def monthly_cost(requests_per_day, input_tokens, output_tokens,
price_in_per_m, price_out_per_m, days=30):
per_request = (input_tokens / 1_000_000 * price_in_per_m
+ output_tokens / 1_000_000 * price_out_per_m)
return per_request * requests_per_day * days
# 2,000 requests/day, 800 tokens in, 150 tokens out,
# $3 per million input tokens, $15 per million output tokens
print(round(monthly_cost(2000, 800, 150, 3.0, 15.0), 2))This prints 279.0. Note that retrieval, long chat histories, and retries all raise the input token count, so measure real traffic once you have it.
Step 4: Cut to the smallest useful slice
Pick one input type, one output format, and one user group. For example, do not build "a support assistant". Build "a classifier that labels incoming tickets as billing, bug, feature request, or other, with a person reviewing anything labeled other".
Design the failure path at the same time. Good first projects keep a person or a deterministic check in the loop:
- Validate structured output and reject anything that fails.
- Return a fallback label or "I don't know" instead of guessing.
- Show sources next to generated answers.
- Require human approval for any action that is hard to undo.
The following function is the whole shape of a well-scoped first feature. It has one prompt, a closed set of answers, and a safe default.
LABELS = ["billing", "bug", "feature_request", "other"]
def classify(ticket: str, complete) -> str:
prompt = (
"Classify the support ticket into exactly one label from: "
+ ", ".join(LABELS)
+ ".\nReply with the label only.\n\nTicket: " + ticket
)
answer = complete(prompt).strip().lower()
return answer if answer in LABELS else "other"Here complete is any function that takes a prompt string and returns the model's reply text. Because it is passed in, you can replace it with a stub in tests.
The decision flow
The diagram summarizes the order of the checks. Note that constraint failures send you back to a smaller scope, not forward to a bigger model.
Fixing a prototype that falls short
When results miss the threshold, look at the failures before changing anything. The fix depends on the kind of error:
- The model misreads the task: improve the instructions and add examples.
- The model lacks facts it could not know: add retrieval.
- The model needs a consistent style or format across many inputs, and prompting has plateaued: consider fine-tuning.
- The task is too broad: narrow it.
Try them in that order. Each step costs more than the one before.
Common scoping errors
- Starting with an agent. The feature works in demos and fails unpredictably in use. Begin with a fixed workflow.
- No test set. Without one, every prompt edit is a guess, and you cannot tell progress from regression.
- Ignoring the error cost. A 95% accurate system can still be unacceptable if the 5% is expensive.
- Treating the model as a database. Facts that must be right belong in your data, supplied by retrieval or a tool.
- Skipping the privacy check. Finding out in week six that the data cannot leave your network wastes the project.
- Scoping to the model's best case. Plan for the typical and worst inputs, not the ones in your demo.
Exercise
A team wants "an AI assistant that handles all customer emails, including issuing refunds". Rewrite this as a well-scoped first project. Name the pattern, the success measure, and one safeguard.
Show answer
One acceptable scope is to classify incoming emails into a few labels such as refund request, shipping question, and other, and to draft a reply only for shipping questions. The pattern is classification with validation, plus a single prompt for drafting. The measure is label accuracy on 50 real emails with a threshold such as 90%, and a person approving every drafted reply. A safeguard is that refunds are never issued by the model. Refund requests go to a person, and the fallback label "other" catches anything uncertain. Tool calling for refunds can come later, after the classifier is measured and trusted.
Exercise
Using the cost function in this chapter, a feature gets 500 requests per day with 2,000 input tokens and 300 output tokens each, at $3 per million input tokens and $15 per million output tokens. What is the monthly cost, and which single change would most reduce it?
Show answer
Per request: 2,000 / 1,000,000 × 3 = $0.006 for input, and 300 / 1,000,000 × 15 = $0.0045 for output, so $0.0105. Over 500 requests a day for 30 days (15,000 requests), the total is $157.50. Input tokens cost more here, so the most effective change is to send fewer of them, for example by retrieving fewer or shorter passages or trimming the instructions. Shortening the output would help less.