Skip to main content
When infer returns a typed AI response, such as a STRUCT, ARRAY, or ENUM, Chowder also measures how confident the model was in each value. The output schema fixes the field names and types. The model’s token log probabilities give a confidence score for each field value. Chowder returns these field-level confidence scores in the AI envelope’s confidence field, as a confidence twin. The twin has the same structure as output, with a score in place of each scalar value. For example, when you classify a customer service message, Chowder returns both the structured AI response and its confidence twin:
Structured output
Confidence twin
These scores are illustrative. Each value and its score share the same path through the structure. For example, confidence.issue_type scores output.issue_type. Each score is a FLOAT between 0 and 1. Like predicted probabilities in traditional ML classification, scores are a signal of model confidence, not a guarantee of correctness.

Why field-level confidence?

A structured response contains values and the structure around them: braces, quotes, punctuation, and field names. The model usually predicts these structural tokens with high confidence, even when a value is wrong. A single score for the whole response mixes confidence in the content with confidence in its formatting. What matters is each value. An uncertain invoice total should not look more trustworthy because the model confidently generated the surrounding JSON. Field-level scores use only the tokens that represent each value.

How Chowder calculates it

Language models generate text one token at a time. Each token has a log probability: how likely the model considered that token, given the prompt and the tokens before it. Token boundaries don’t follow the JSON structure. A string can span several tokens, and one token can contain part of a value and the punctuation around it. To score a value, Chowder:
  1. Parses the generated JSON and finds the exact text of each scalar value: strings (including their quotes), numbers, Booleans, and nulls.
  2. Finds the smallest run of whole tokens that contains that text.
  3. Combines those tokens’ probabilities with their geometric mean.
The geometric mean is the exponential of the mean log probability:
Here, pᵢ is the probability of token i, and n is the number of tokens in the value. Chowder uses the geometric mean because:
  • Probabilities multiply. The probability of a token sequence is the product of its token probabilities. The geometric mean keeps that structure.
  • It penalizes weak tokens. An arithmetic mean can hide a very low probability behind high ones. The geometric mean is more sensitive to it.
  • It normalizes for length. Taking the nth root makes scores comparable across values with different numbers of tokens.
Chowder tracks each value by its position in the structure, so nested objects, arrays, and repeated values each get their own score.

Query confidence in SQL

Declare the output schema in infer. Chowder returns the values in output and their scores in confidence:
Scores are regular SQL values. Select them alongside the output, filter on individual fields, or group by them to find patterns. For example, replace the final SELECT to keep only rows where the model is confident in the issue type:
The 0.7 threshold is illustrative. The example can return no rows if the predicted issue type scores below that threshold. See Choose thresholds.

Confidence by output type

How Chowder computes confidence depends on the input and output schema: A TEXT score measures how likely the model found its exact wording, not whether the response is correct. Free-form responses can be phrased many ways, so a good response can still score low. For values you want to filter or threshold, use a typed schema such as STRUCT, ARRAY, or ENUM.

When confidence is null

confidence is null when:
  • The row failed, so output is null and error explains why.
  • Chowder can’t safely align tokens with values. It keeps the valid output and explains the failure in error. Chowder doesn’t cache the result, so a later query retries it.

Choose thresholds

Different fields can lead to different decisions. You can accept a predicted category while sending an uncertain invoice amount for review. Field-level scores let you make those decisions separately, in the same SQL query as the outputs. Scores depend on the output schema. The same value can score differently as a standalone value and as a STRUCT field, so choose thresholds for each schema. Labels that share words, such as 'very positive' and 'very negative', can score higher, because the model is confident in the shared tokens. A model can still give an incorrect AI response with high confidence. Choose thresholds using representative labeled data, and revisit them when the model, prompt, or output schema changes. For the full walkthrough, read Field-level confidence scores for structured AI outputs on the Chowder blog.