Expand description
grounding of the llm node: the answer is checked against its sources before it leaves.
- id: write_reply
type: llm
context: { enabled: true, variable_selector: [retrieve, result] }
grounding:
facts: [[sys, chatbot_facts], [lookup, body]] # what the answer may state
customer: [[start, message]] # whose numbers it may repeat
fallback: "Sorry, I don't have that information yet."
confirm: model # optional, see belowThe facts are the listed values (missing ones are skipped) and the node’s own context
(the knowledge passages it answers from). The prompt is not a source: a builder model may
have written it, and a made-up fact in a prompt is still made up.
The answer is checked by graphrt_core::grounding: sentences that state a number, a
day, an address or words the sources do not hold are left out; when no sentence the facts
hold is left, text is the fallback (a template) and grounded is false, for the
workflow (or its host) to hand over. Answers are not streamed while grounding is on: only
the checked text may reach anyone.
confirm: model asks the node’s model once more, and only when the words check left out a
sentence (a paraphrase or another language can miss a true one): one short call, at
temperature 0, that names the sentences the facts hold. Numbers, days and addresses are
never left to it. Its usage is the node’s.
Outputs: text, grounded (bool), unknown (bool: the answer says it does not know
something the customer asked, “I’m not sure about a vegan menu”; with nothing else it is the
fallback too), draft (the model’s answer as written),
unsupported ([{sentence, reason}]), and with a confirming call confirmed (the sentences
the model kept) and check_usage (its tokens).
§Numbers only (check: numbers)
A report may word its figures freely, but every figure must be one of the facts:
grounding:
facts: [[figures, json]]
check: numbers
numbers: { tolerance: rounding, ratios_as_percent: true }
on_fail: output # keep the draft and report, or `fallback` (the default)Every number of the answer is compared with the numbers of the facts by
graphrt_core::grounding::figures (rounding, percentages and ratios, notations). With
structured output every string of structured_output is checked, and each unsupported
number is reported with the path of its field. Outputs: grounded (bool) and unsupported
([{field, number, sentence, reason}]). With on_fail: fallback a text answer with an
unsupported number becomes the fallback and draft keeps it; on_fail: output changes
nothing; on_fail: error fails the node (for an on_error branch).
§Attribution (attribution)
A true number can still stand next to the wrong entity. With attribution, the facts are
also grouped by entity, and every figure must stand next to an entity that holds it
(graphrt_core::grounding::entities):
grounding:
facts: [[figures, json]]
check: numbers
attribution:
entities: [[prep, categories], { from: [figures, json, stores], label: name }]
groups: [all categories] # group words that name no entity
scopes: { "stores[*].note": "{{#prep.top_store#}}" } # or [prep, scopes]
skip: { integers_up_to: 10 }
on_fail: outputA misattributed figure is reported in unsupported with reason: attribution, the entity
the text gives it to (named) and the entities whose facts hold it (owners).
Structs§
- Grounding
Config - The
groundingblock of anllmnode. - Numbers
Config numbersof agroundingblock: how numbers are compared.