Glossary

Logprobs

The log probabilities a language model assigned to the tokens it generated, and often to the closest alternatives, returned by an API as a measure of how confident each choice was.

Logprobs, short for log probabilities, are the probabilities a language model assigned to each token it generated, expressed as natural logarithms. Many model APIs can return them alongside the output: for every generated token you get its logprob and, if requested, the logprobs of the few most likely alternatives the model considered at that step. A logprob of 0 means the model was certain (100%), about -0.69 means 50%, and about -2.3 means 10%. Logprobs are the most direct view an application has into how confident a model was in each part of its answer. Teams use them to score classifications, flag uncertain extracted fields for review, compare candidate answers, measure how surprising text is to a model and debug prompts. They describe the model’s confidence, which is different from whether the answer is correct.

Where logprobs come from

At every generation step, a transformer produces a score for every token in its vocabulary, and a softmax turns those scores into probabilities. The model then picks one token, shaped by sampling settings such as temperature and top-p. The logprob of that token is the natural log of the probability it had at that moment. When an API offers top alternatives, usually up to a small fixed number per position, it returns the next most likely tokens with their logprobs too, so you can see what the model nearly said.

Logarithms are used because the probability of a whole sequence is the product of the probabilities of each token, and multiplying hundreds of small numbers quickly becomes too small for a computer to store accurately. Adding logs is equivalent and stable. The logprob of a sentence is the sum of the logprobs of its tokens, and dividing by the number of tokens gives an average that can be compared across texts of different lengths.

Logprob

Probability

How to read it

0

100%

Certain; no other token had meaningful weight

-0.05

about 95%

Very confident

-0.69

about 50%

A coin flip between this and another token

-2.3

about 10%

An unlikely choice that sampling happened to pick

-4.6

about 1%

Very unlikely; often a sign of a slip

To convert, take e to the power of the logprob: e^-0.69 is about 0.5. Because tokens come from byte pair encoding, a single word may be several tokens, and the confidence in the word is the product of their probabilities, or the sum of their logprobs. The first token of a word usually carries most of the uncertainty; once a model has started “Lond”, “on” is close to certain.

Requesting and storing logprobs

In most APIs that support them, logprobs are off by default and switched on per request with a flag, plus an optional count of alternatives to return at each position. The response then carries, for every generated token, the token text, its logprob and the list of alternatives. That roughly multiplies the size of the response by the number of alternatives requested, so ask only for what you will use: the chosen-token logprob is enough for field confidence, while alternatives matter for classification and debugging.

Store logprobs with the output, the prompt version, the model name and the sampling settings. A confidence score without that context cannot be compared from one week to the next. Most LLM observability tools can record them, and plotting the share of low-confidence outputs over time is a cheap early warning that a prompt change, a new model version or a shift in input data has made the system less sure of itself. Logprobs count towards nothing in billing by themselves; the input and output tokens cost the same either way.

What logprobs are used for

Classification with a confidence score

For a yes or no question, a sentiment label or a routing decision, ask the model to answer with a single token and read the logprobs of each allowed label at that position. Instead of a bare label you get a distribution, such as 92% “refund” and 6% “billing”, which lets you set a threshold, send borderline cases to a person, or compare scores across thousands of items. This is often cheaper and more stable than asking the model to state its confidence in words, which models do poorly.

Flagging uncertain extracted fields

In structured output and key-value extraction, logprobs show which fields the model was unsure about. An invoice total generated with every digit above 99% is likely to be what the model read; one where the third digit was a 55% choice over another digit deserves a second look. Taking the lowest token logprob within each field, rather than the average, catches the one shaky character that an average would hide. Fields under a threshold can be routed to human-in-the-loop review while the rest flow straight through.

Spotting likely hallucinations

Low-probability stretches in an answer are a useful, imperfect signal of hallucination. A name or date generated with low confidence, where the alternatives were other names or dates, suggests the model was guessing. The signal fails in the other direction: a model can be highly confident and wrong, especially when the prompt contains a plausible but outdated fact. Logprobs therefore work best alongside checks of faithfulness to the source material rather than in place of them.

Routing and escalation

Confidence can decide what happens next. With model routing, a small, cheap model handles every request first, and anything it answers with low confidence is passed to a larger model or to a person. The same idea works inside guardrails: a low-confidence answer to a policy question can trigger a safer fallback, such as quoting the source passage instead of paraphrasing it. These rules are only as good as the thresholds behind them, which brings the calibration question below back into play.

Evaluation, ranking and debugging

Perplexity, a standard measure in language modelling, is the exponential of the negative average logprob of a text: lower perplexity means the text was less surprising to the model. Logprobs also let you rank several candidate completions by how likely the model finds each, score multiple-choice questions in LLM evaluation without parsing free text, and make LLM-as-a-judge scores more fine-grained by reading the probabilities of each score token. When debugging a prompt, the top alternatives at the point where an answer went wrong often show exactly which misleading phrase pulled the model off course.

Limits and pitfalls

Logprobs measure confidence, and confidence is not the same as accuracy. Models tuned with RLHF and similar methods tend to be less well calibrated than base models: a 90% token is right less than 90% of the time in some settings. Calibrate any threshold on your own labelled data, such as a golden dataset, before relying on it. Thresholds also drift when you change models, prompts or sampling settings, so they need re-checking with each change.

Availability varies. Some providers return logprobs for every model, some only for certain ones, and some reasoning models do not return them or return them only for the final answer, not the hidden reasoning. Providers differ on whether reported values reflect the distribution before or after temperature is applied, so check the documentation for the model you use. Under constrained decoding or JSON mode, tokens that the schema forbids are removed, which can make structural tokens look certain even when the model would have preferred something else. Requesting logprobs also adds to response size and, with some providers, to latency.

A worked example: routing invoice fields for review

Consider a team doing invoice processing with a language model that turns extracted invoice text into JSON with vendor, due date and total. They request logprobs and compute, for each field, the lowest token logprob inside its value. On a sample of 500 invoices checked by hand, fields with a minimum logprob above -0.2 (roughly 82%) are correct 99.6% of the time, while fields below -1.0 (roughly 37%) are wrong about a third of the time. The team sends any invoice with a field below -0.5 to a reviewer, which turns out to be about 4% of invoices, and lets the rest through.

Reviewing the flagged cases shows a pattern: most low-confidence totals come from invoices where the input text had lost the table layout, so the model was choosing between a subtotal and a total. Better input removed most of those flags. Logprobs found where the problem was; fixing the input fixed it. All figures in this example are illustrative.

Where Exabase fits

Exabase does not return model logprobs, because it does not run your generation calls; logprobs come from whichever model provider you use. It improves what the model reads and adds confidence signals on the retrieval side. Extract recognises invoices, resumes and contracts and returns structured fields such as invoice number, issue date, due date, line items and total, which removes the layout guesswork behind many low-confidence fields; the retrieving results guide shows the response, the invoice to JSON tool runs it on a single file, and file extraction covers the wider approach. For what typically goes wrong in this kind of pipeline, see what breaks invoice extraction.

Deep Search returns a relevance score for every hit and every matched chunk, with page numbers and timestamps, through the search endpoint. Exabase Memory returns a score with each memory it retrieves. A low retrieval score combined with low generation logprobs is a strong reason for an agent to say it is unsure or ask for help, which is part of the approach in RAG accuracy. For comparisons of extraction services, see the best invoice extraction API and best document extraction API pages.

Frequently asked questions

What are logprobs in simple terms?

They are the model’s confidence in each token it wrote, given as the natural log of a probability. A value near 0 means very confident; more negative values mean less confident.

How do I convert a logprob to a probability?

Raise e to the power of the logprob. For example, e^-0.69 is about 0.5, so a logprob of -0.69 means a 50% probability.

Why are logprobs negative?

Probabilities are between 0 and 1, and the logarithm of any number in that range is zero or negative. Only a certain token, with probability 1, has a logprob of 0.

Can logprobs detect hallucinations?

Partly. Low logprobs on names, numbers or dates often mean the model was guessing, but models can be confidently wrong, so combine logprobs with checks against the source. See hallucination.

What is the difference between logprobs and perplexity?

Logprobs are per token. Perplexity summarises a whole text as the exponential of the negative average logprob, so lower perplexity means the text was more predictable to the model.

Do all models return logprobs?

No. Support depends on the provider and model, and some reasoning models return none or only partial values. Check the documentation for the model you call.

Does Exabase provide logprobs?

No. Logprobs come from your model provider. Exabase provides relevance scores for retrieved memories and passages through Memory and Deep Search, which you can combine with logprobs to decide when an agent should be cautious.

Related pages: temperature, top-p sampling, token, hallucination, structured output, LLM evaluation, relevance score, byte pair encoding, file extraction

Cut your token spend and give your agent precise context.

Get started in minutes.

Cut your token spend and give your agent precise context.

Get started in minutes.