Sub topic 13
Choosing Between Prompting and Fine-Tuning
This chapter assumes that you know basic Python and JSON, understand what a language model does, and know the introductory definitions of precision, recall, and F1. You also need a labeled evaluation set before making a reliable choice.
Information extraction turns text into fields, entities, or relationships. Two common approaches are:
- Prompting: ask a general-purpose language model to extract the required information.
- Fine-tuning: train a model further on examples that show the desired outputs.
Neither approach is always better. The right choice depends on accuracy, data, cost, latency, and how often the schema changes.
Compare the main trade-offs
| Factor | Prompting | Fine-tuning |
|---|---|---|
| Initial data need | None to a small example set | A labeled training set |
| Schema changes | Usually quick to support | Often requires new training |
| Accuracy on stable domain language | Good, but variable | Often more consistent |
| Per-request cost | Can be higher | Usually lower after training |
| Latency | Often higher | Usually lower with a small model |
| Debugging | Inspect prompts and outputs | Inspect data, labels, and model behavior |
| Best fit | Changing tasks and early prototypes | High-volume, stable production tasks |
Prompting is usually the fastest way to test whether extraction is feasible. You can describe the schema, show a few examples, and validate the returned JSON. This approach works well when documents vary widely or requirements are still changing.
Fine-tuning becomes attractive when the task has stable rules, many repeated requests, and enough representative labels. A token-classification model can learn where entities begin and end. A generative model can learn to produce a particular structured format. Fine-tuning can reduce cost and latency, but training data becomes part of the system that you must maintain.
Use an evaluation-first decision process
Do not choose based only on a few impressive examples. Run both approaches, when practical, on the same held-out gold dataset. A held-out set is labeled data that was not used to design prompts or train the model.
Measure exact span-level precision, recall, and F1 for entities. For fields such as total or currency, also measure field-level accuracy and whether the output passes schema validation. Track invalid JSON separately from semantic extraction errors.
A useful process is:
- Define the extraction schema and labeling rules.
- Create a representative gold dataset.
- Establish a prompted baseline with zero-shot or few-shot examples.
- Record quality, invalid-output rate, latency, and cost.
- Train or test a smaller fine-tuned model if the task is stable.
- Compare results at the expected production volume.
- Choose the simplest approach that meets the acceptance threshold.
The acceptance threshold should reflect the consequence of errors. A wrong product category may be tolerable. A wrong legal clause, medical attribute, or invoice amount may require human review.
Recognize when each approach fits
Choose prompting when:
- The schema or business rules change often.
- You have little labeled data.
- The task needs broad language understanding.
- Request volume is low or moderate.
- A human can review uncertain outputs.
- You need to support a new task quickly.
Choose fine-tuning when:
- The labels and output behavior are well defined.
- You have enough examples covering real variation.
- The same extraction runs at high volume.
- A smaller model can meet the quality target.
- Stable latency and predictable behavior matter.
- You can version and retrain the model when the data changes.
A hybrid pipeline often gives the best operational result. An LLM can label or normalize difficult examples, while a smaller fine-tuned model handles routine traffic. A confidence threshold can route uncertain cases to the LLM or a human reviewer. Validation should remain in place regardless of the model.
Make the decision reversible
Start with a prompted baseline and a small but representative evaluation set. Keep the schema, labels, prompts, model versions, and metrics under version control. If the prompted system meets the target, deploy it while monitoring drift. If volume, latency, or cost later becomes a problem, use the collected examples to train a smaller model.
The decision is also a risk decision. When errors are expensive, prefer explicit validation, abstention, and human review over a system that always returns an answer. A model that returns null for unknown information can be safer than one that confidently guesses.
Exercise
A team has 2,000 labeled examples, a stable invoice schema, and ten million documents per month. A prompted model meets the F1 target but costs too much and has high latency. What should the team test next, and what must it compare?
Show answer
It should test a fine-tuned smaller model. It must compare span or field quality, invalid-output rate, latency, inference cost, maintenance effort, and behavior on a held-out dataset.