Skip to content

8.7 Extraction rules

A summary; the binding text is CLAUDE.md, "Extraction rules", and the account is the extraction guide (docs/guides/structured-llm-response.md). In the code, the one validation boundary every adapter's text answer passes is ExtractionResponseParser; Spring AI's StructuredOutputValidationAdvisor re-asks on a schema violation inside ExtractionLoop; a confirmed value carries page and passage (ExtractedField); the verdict is FieldConfidence (CLAUDE.md, "Architecture").

  1. Fixed schema. The two contract partners, vendor and assetCo, each grouped into its facts (name, partner number) and its address (e-mail, street, postcode, city, country), and contractId — fifteen fields, each a list of candidates, each candidate a value with the passage it was read from; an address candidate also names the kind of address (ExtractionClaim). Extra fields are discarded. The list exists because a model asked for one value in a document that carries three returns the first one it saw.
  2. An empty field is a valid result; an invented field is a bug. When in doubt, return nothing.
  3. Every model response is validated before it reaches domain code; non-JSON answers and timeouts get a defined fallback, not a stack trace. Mistakes of the model become the fallback; mistakes of the caller are reported.
  4. Confidence is derived, never reported. GROUNDED, UNSUPPORTED, AMBIGUOUS, NOT_FOUND come from the citation check; the model is never asked how sure it is. The check catches an invented value; it does not catch a real passage quoted for the wrong field.
  5. An UNSUPPORTED value is kept for the reviewer, flagged, and never counts as confirmed; the extraction is then incomplete — extractionComplete is false.
  6. Several different values for one field is a report, not a choice: the field stays empty and AMBIGUOUS. Never pick the first; never write the rule as "the field occurs several times".
  7. No contract content in any log, at any level — the competing values and the raw answer are not logged; tests assert on the returned result instead (G-6).
  8. Schema validation does not catch a plausible lie. What catches it is a test against a document known not to contain the value.

Where the per-field confidence comes from. For the extraction, confidence is the FieldConfidence verdict derived from the citation check, never reported by the model (CLAUDE.md, "Extraction rules"; extraction guide (docs/guides/structured-llm-response.md)). ConfidenceBand is kept for the reconciliation side only and is never produced by the extraction. Its carrier entity and thresholds are open. The three vocabularies are told apart in the glossary.