ClarifierNode
Reference for the node that asks the user which reading of an ambiguous question they meant, for contributors and operators.
Overview
- Asks instead of guessing: when the planner read a phrase of the question in more than one way, and two or three readings pass the checks, it ends the sub-query with the options rather than running the most likely one.
- Sits on the logical validator's "valid" edge, before the generator, so every path from the planner to the generator still passes the validator.
- Makes no model call.
- Class:
ClarifierNode - Source:
packages/nl2sql/src/nl2sql/pipeline/nodes/clarifier/node.py-.
Responsibilities
- Run each of the planner's alternative readings through the validator's own
checks (
LogicalValidatorNode.check: the static checks and the caller's scope) and drop those that fail. A reading that names a table the caller cannot read is never offered, and never listed as an assumption. - Render each remaining reading to SQL with the generator and drop one whose SQL another option already has (the default reading comes first). At most three options: the default and two alternatives.
- End the sub-query with
NEEDS_CLARIFICATIONwhen it may ask, and publishclarification.requested. - Otherwise let the default plan go on, keeping the readings that passed on
ast_planner_response.alternatives, which the explanation lists as assumptions.
Position in Execution Graph
Upstream:
- LogicalValidatorNode, when the plan passed
Downstream:
- GeneratorNode, unless it asked
- END, when it asked
flowchart LR
Validator[LogicalValidatorNode] -->|valid| Clarifier[ClarifierNode]
Clarifier -->|ok| Generator[GeneratorNode]
Clarifier -->|asked| End[END]
Inputs
From SubgraphExecutionState:
ast_planner_response.plan,ambiguous_phraseandalternatives. Each alternative already went throughplan.afterin the planner node, as the plan did: one a hook denied is not there, one a hook changed is there as changed.sub_query,relevant_tablesanduser_context, for the validator's checks.clarify: set bywrap_subgraphwhen the run'sclarifyis on and the sub-query is the run's only one.
From the runtime: settings.clarify.enabled, and the run's pinned knowledge
for the datasource's knowledge digest.
Outputs
- No alternatives: nothing (it passes straight through).
- Otherwise
ast_planner_responsewithalternativescut to the readings that passed and were not merged.alternatives_offered(every reading the planner gave, set by the planner node) is left as it is, so an answer with readings is never cached, even when none was left for this caller. - When it asks, also one
PipelineError:NEEDS_CLARIFICATION, severityINFO, never retried. Itsdetailscarry what the result needs to build theClarificationRequest:phrase,datasource_id,schema_version,knowledge_digest,sub_queryandoptions(id,label,plan; the default reading,a, has no label from the planner). The result adds the question, the asker and each option's explanation (result_from_stateinapi/query_api.py).
When it asks
All of these hold:
- The planner named the phrase (
ambiguous_phrase) and at least one alternative passed the checks and was not merged. A phrase the glossary settles is not asked: the flag and the alternatives are dropped and the default plan goes on. A phrase is settled when a term's name equals it, or exactly one term lists it as a synonym (case-insensitive); "sales" listed by two terms stays open. The plan is still never cached, since the planner's answer carried readings (alternatives_offered). state.clarifyis on: the run'sclarify(run_query(clarify=...), default true; evals pass false) and the run has exactly one sub-query.settings.clarify.enabledis on (the default).- No attempt of the sub-query has executed yet. After a sanity retry
(
VALUE_NOT_FOUND,JOIN_FAN_OUT) the re-plan's default reading runs, so the flagged attempt's rows are never the answer, and the readings that passed are assumptions.wrap_subgraphnever counts a sub-query that asked as succeeded, nor returns its artifact.
The prompts are the same either way: clarify only decides whether the
clarifier ends the run.
Contracts & Interfaces
check_clarifier in build_sql_agent_graph routes end when the state holds
a NEEDS_CLARIFICATION error, else ok. The layer router ends the run on it
(nothing is executed, aggregated or synthesized), and wrap_subgraph reports
the sub-query with status needs_clarification and no MISSING_SQL error.
Observability
clarification.requested(sub_query_id,phrase,options), an operator event, never on the caller's stream.- No
policy.decisionand no denial warning for an alternative that names a denied table (check(..., audit=False)): that reading is dropped and reaches no caller. The plan the caller gets is audited as always. node.startedandnode.finishedas every step.
Related Code
packages/nl2sql/src/nl2sql/pipeline/nodes/clarifier/node.pypackages/nl2sql/src/nl2sql/pipeline/subgraphs/sql_agent.pypackages/nl2sql/src/nl2sql/api/query_api.py(result_from_state)packages/nl2sql/tests/unit/test_clarifier.py