A language model can behave like a classifier without any parameter updates: give it a few labeled examples, present a new input, and ask it to choose a label. The surprising problem is that the answer can depend not only on the new input, but also on details such as the prompt wording, demonstration order, and label tokens.

That creates a practical debugging trap. A prompt may appear to teach the task while also giving the model a baseline preference for one answer before meaningful input is considered.

Contextual calibration is a simple way to measure and compensate for that preference. The core idea is to run the same classification prompt with a content-free input, treat the resulting label distribution as a prompt-specific baseline, and correct real predictions relative to that baseline.

This article develops that mental model, works through a small numerical example, and explains where the method helps, where it does not, and what to measure before relying on it.

Start with the bias you can observe

Suppose a few-shot prompt classifies support messages as billing or technical:

Message: I was charged twice.
Label: billing

Message: The app crashes after login.
Label: technical

Message: <new message>
Label:

Assume the model interface lets you obtain probabilities for the two candidate labels. For a new message, it returns:

billing:   0.60
technical: 0.40

Taking the largest probability produces billing. But first ask a different question: what does this prompt predict when the input contains no useful evidence?

Replace the new message with a content-free value such as N/A, while leaving the demonstrations and formatting unchanged:

Message: N/A
Label:

Imagine the model now returns:

billing:   0.75
technical: 0.25

That distribution is informative. The prompt already favors billing three to one even when the test input says nothing about the task.

Contextual calibration treats this distribution as a baseline rather than as evidence about any real example.

The mental model: compare evidence against the prompt baseline

Let p(y | x) be the model’s probability for label y on real input x. Let p(y | cf) be its probability for the same label when the test input is replaced by a content-free input cf.

A useful way to express the correction is:

adjusted_score(y) = p(y | x) / p(y | cf)

Then normalize the adjusted scores across the candidate labels if you need a distribution.

For the example above:

billing:   0.60 / 0.75 = 0.80
technical: 0.40 / 0.25 = 1.60

After normalization:

billing:   0.80 / 2.40 = 0.333
technical: 1.60 / 2.40 = 0.667

The calibrated decision is technical.

Why did the result flip? The raw probability for billing was larger, but much of that preference was already present with no meaningful input. The technical score increased more relative to its own baseline.

This is the key mental model: do not ask only which label the model likes most; ask which label the actual input supports more than the prompt already did.

Where the baseline preference comes from

Few-shot prompting does not create a clean classification layer. The model is still predicting text from text, so the exact prompt changes the context in which candidate labels are scored.

Several effects can shift the baseline distribution. A label token may be more common in the model’s learned text distribution. Demonstrations can make recently shown labels easier to continue. Formatting and wording can also change which completion looks natural.

The original contextual-calibration work showed that few-shot performance could vary substantially with prompt format, demonstration choice, and demonstration order. Its proposed correction estimates the model’s answer bias with a content-free input and calibrates predictions so that this baseline does not dominate the task signal.

The important engineering implication is not that every prompt has a harmful bias. It is that a baseline preference is measurable, so you can test for it instead of assuming the prompt is neutral.

Implement the smallest useful version

For a classifier with a fixed set of single-token labels and access to their probabilities, the procedure is compact:

baseline = label_probabilities(prompt, input="N/A")

for input in evaluation_examples:
    raw = label_probabilities(prompt, input=input)

    for label in labels:
        score[label] = raw[label] / baseline[label]

    prediction = argmax(score)

In numerical code, log probabilities are usually more convenient because division becomes subtraction:

calibrated_log_score(label) =
    log_p(label | input) - log_p(label | content_free_input)

The label with the largest calibrated log score is also the label with the largest probability ratio.

This teaching example assumes the interface exposes comparable probabilities or log probabilities for every candidate label. Some model APIs expose only generated text, expose log probabilities only in certain modes, or do not make arbitrary candidate scoring convenient. Contextual calibration is not directly available when you cannot obtain comparable label scores.

Keep the scoring setup controlled

Calibration is meaningful only when the baseline and real examples use the same scoring setup.

Keep the demonstrations, instructions, separators, label spellings, and generation position unchanged. Replace only the test content. If the baseline prompt and real prompt differ in other ways, the subtraction can remove effects that are unrelated to the baseline you intended to measure.

For an initial implementation, prefer labels that map cleanly to one token under the model’s tokenizer. Multi-token labels introduce another issue: their probability is a product of conditional token probabilities, so longer or differently tokenized labels may not be directly comparable without a deliberate sequence-scoring rule. That problem exists even before contextual calibration.

If your production labels are human-readable phrases, an internal mapping can simplify scoring:

A -> billing
B -> technical
C -> account

You can ask the model to predict A, B, or C, then map the result back to the application label. This does not guarantee neutrality, but it makes the candidate set easier to score consistently.

Choose content-free inputs carefully

N/A is useful because it carries little task-specific information in many settings, but no string is universally content-free. For a task about missing values, for example, N/A may itself have semantic meaning.

A practical approach is to try a small set of neutral candidates such as:

N/A
[empty]
unknown

Here [empty] means an actually empty test field, not necessarily the literal word. Inspect whether the resulting baseline distributions are similar. Large differences indicate that your supposed neutral inputs are interacting with the task or prompt.

Do not silently average arbitrary baselines and assume the result is better. First understand why they differ. The baseline is part of the classifier specification and should be fixed and evaluated like other prompt choices.

Evaluate calibration as a model change

A corrected score is not automatically a better classifier. Measure it on held-out labeled examples.

At minimum, compare raw and calibrated versions using the task metric you actually care about. Accuracy may be sufficient for balanced, equal-cost classes. Precision, recall, per-class error rates, or a cost-weighted metric may be more appropriate when mistakes have different consequences.

Also compare the confusion matrices. Calibration can improve aggregate accuracy while shifting errors toward a class that matters more operationally.

A useful experiment is:

                 raw prompt    calibrated
accuracy             ...           ...
billing recall       ...           ...
technical recall     ...           ...

Repeat the comparison across a few reasonable demonstration orders or prompt variants. One motivation for contextual calibration is reducing sensitivity to these choices, so stability is itself worth measuring.

Keep the evaluation set separate from prompt construction. If you repeatedly select prompts, labels, or content-free inputs based on the same test set, that set becomes part of development and no longer provides an unbiased final estimate.

Understand what contextual calibration does not fix

Contextual calibration corrects a narrow problem: a prompt-specific preference over candidate answers. It does not repair every failure in an LLM classifier.

If demonstrations contain wrong labels, calibration cannot restore the missing supervision. If classes are poorly defined, dividing scores by a baseline does not make the boundary clearer. If the input exceeds the model’s usable context or important evidence is buried in irrelevant text, the method does not recover that evidence.

It also does not turn model probabilities into guaranteed real-world probabilities. A calibrated score in this procedure is primarily useful for comparing candidate answers after correcting a prompt baseline. If your application needs probabilities with a particular empirical interpretation, evaluate probability calibration separately on representative labeled data.

Finally, a strongly skewed baseline can be a symptom worth fixing rather than merely compensating for. If one demonstration order creates extreme bias and another reasonable order does not, simplifying or balancing the prompt may be the cleaner solution.

Consider simpler alternatives first

Contextual calibration is most attractive when you already have a fixed-label few-shot classifier, can access candidate scores, and observe sensitivity to prompt details.

A simpler change may be preferable when the source of the problem is obvious. Balance the demonstrations if one class is overrepresented accidentally. Use clearer label descriptions if classes are ambiguous. Remove unnecessary examples if the prompt has become long and contradictory. For a stable task with enough labeled data, a conventional trained classifier may also be easier to evaluate and operate than an LLM prompt.

The method is therefore best treated as one tool in a diagnostic sequence:

validate labels and examples
        |
        v
measure raw prompt behavior
        |
        v
measure content-free baseline
        |
        v
apply contextual calibration
        |
        v
compare on held-out data

If calibration improves the metrics and stability that matter to the application, keep it. If it merely moves errors around, prefer the simpler raw classifier or address the underlying prompt design.

Conclusion

Few-shot classification prompts can carry their own answer preference. Contextual calibration makes that preference visible by scoring a content-free input, then evaluates real inputs relative to the measured baseline.

The technique is simple, but its value comes from disciplined use: keep scoring conditions identical, choose genuinely neutral baseline inputs, use comparable candidate-label scores, and validate the correction on held-out data. The broader lesson is reusable beyond this method: when a model makes a decision from a prompt, measure what the prompt contributes before attributing the entire output to the user’s input.