Sub topic 11
Comparing Cost, Latency and Maintenance
Assume you know basic Python, JSON, language models, and introductory precision, recall, and F1. This chapter focuses on operating an information-extraction system after you have defined its schema and measured its quality.
A prompting system asks a general-purpose language model to extract fields from each document. A fine-tuned model learns the extraction behavior from labeled examples. Both approaches have costs beyond the model call itself.
What to include in the cost
Compare the full cost of one extracted document, not only the price listed by a model provider.
For a prompted system, the main costs are:
- Input and output tokens.
- Retries when the response is invalid.
- Validation and repair calls.
- Prompt development and testing.
- Model hosting or provider charges.
- Human review of uncertain results.
For a fine-tuned system, the main costs are:
- Collecting and labeling training examples.
- Training or fine-tuning runs.
- Model hosting and infrastructure.
- Periodic retraining as the data changes.
- Engineering work for preprocessing, deployment, and monitoring.
A prompted system often has a lower initial cost. A fine-tuned system can have a lower cost per document when volume is high and the model is small.
| Cost dimension | Prompting a general model | Fine-tuned model |
|---|---|---|
| Initial setup | Usually low | Higher because labeled data is needed |
| Per-document cost | Often tied to tokens | Often low after deployment |
| Infrastructure | May be managed by a provider | Usually your responsibility |
| Updating behavior | Change the prompt or model | Collect data and retrain |
| Operational complexity | Lower at first | Higher, especially for deployment |
| Best volume profile | Low or changing volume | Stable, high-volume workloads |
Latency is a pipeline property
Latency is the time from receiving a document to producing an accepted result. A single model call is only one part of that time.
A prompt-based pipeline may include document upload, text extraction, a remote API call, JSON validation, and a retry. Long documents and long few-shot examples increase input processing time. A large output schema can also increase generation time.
A fine-tuned token classifier usually runs locally or in a dedicated inference service. Its latency is often more predictable. However, loading the model, batching requests, transferring documents, and running post-processing still add delay.
Measure latency with percentiles, not only averages. The p50 is the median request time. The p95 is the time that 95% of requests finish within. A system with a low average but a high p95 may still violate a user-facing deadline.
Maintenance and change
Maintenance means keeping quality, cost, and availability within acceptable limits as inputs and requirements change.
Prompted extraction is easy to change. You can add an example, clarify a null rule, or switch models without rebuilding an inference service. This flexibility can also create instability. A provider may change a model, and a prompt that worked last month may produce different results after that change.
Fine-tuned extraction gives you more control over model behavior and versioning. You can keep a known model artifact and deploy it repeatedly. Its weakness is adaptation. When vendors, document formats, or writing styles change, the training data may no longer represent production traffic.
Track these signals for either approach:
- Exact-match precision, recall, and F1 on a fixed evaluation set.
- Invalid structured-output rate.
- Human-review rate.
- p50 and p95 latency.
- Cost per document.
- Failure rate by document type.
- Drift in input vocabulary, format, or class frequencies.
Choosing by workload
Choose prompting when the schema is changing, labeled data is scarce, or the document volume is modest. Prompting also works well when broad language coverage matters more than predictable latency.
Choose fine-tuning when the schema is stable, you have representative labeled data, and volume justifies a controlled inference service. A smaller fine-tuned model may be faster, cheaper, and easier to run at scale.
Use a hybrid when the common path is regular but difficult cases need broader reasoning. For example, a fine-tuned model can process ordinary invoices, while a prompted model handles low-confidence documents. This design requires a reliable confidence or routing rule. Otherwise, every document may take both paths and eliminate the expected savings.
Exercise
A team receives 500 documents per month, has 30 labeled examples, and changes its extraction schema every few weeks. Which approach is the better starting point, and what should the team measure?
Show answer
Start with prompting. Measure span-level quality, invalid-output rate, p95 latency, cost per document, and human-review rate. Reconsider fine-tuning after the schema stabilizes and more representative labels exist.