AnswerSynthesizerNode
Overview
- Summarizes aggregated results into a user‑facing response using an LLM.
- Exists to convert structured results into human‑readable output.
- Sits after
EngineAggregatorNodeat the end of the control graph. - Class:
AnswerSynthesizerNode - Source:
packages/nl2sql/src/nl2sql/pipeline/nodes/answer_synthesizer/node.py
Responsibilities
- Serialize aggregated results for prompt input.
- Include unmapped sub‑queries in the response context.
- Invoke LLM with structured output schema.
Position in Execution Graph
Upstream:
- EngineAggregatorNode
Downstream: - Graph end.
Trigger conditions: - Executed after aggregation completes.
flowchart LR
Aggregator[EngineAggregatorNode] --> Synthesizer[AnswerSynthesizerNode] --> EndNode[PipelineEnd]
Inputs
From GraphState:
user_query(required)aggregator_response.terminal_results(required)decomposer_response.unmapped_subqueries(optional)
Validation performed:
- If no aggregated result is available, emits
INVALID_STATE.
Outputs
Mutations to GraphState:
answer_synthesizer_response(AnswerSynthesizerResponse)reasoningsummaryerrorson failure
Side effects:
- LLM invocation.
Internal Flow (Step-by-Step)
- Resolve aggregated result from
aggregator_response. - If missing, emit
INVALID_STATEerror and stop. - Serialize results to JSON.
- Serialize unmapped sub‑queries to JSON.
- Invoke LLM chain with structured output.
- Return
AnswerSynthesizerResponse. - On exception, emit
AGGREGATOR_FAILED.
Contracts & Interfaces
Implements a LangGraph node callable:
Key contracts:
AggregatedResponseAnswerSynthesizerResponse
Determinism Guarantees
- Non‑deterministic unless LLM configured deterministically.
Error Handling
Emits PipelineError with:
INVALID_STATE(no aggregated result)AGGREGATOR_FAILED(LLM failure)
Logs failures via logger.error.
Retry + Idempotency
- No internal retry logic.
- Idempotency depends on LLM determinism.
Performance Characteristics
- LLM call dominates latency and cost.
- Serialization of aggregated results is in‑memory.
Observability
- Logger:
answer_synthesizer - Adds reasoning summary to state.
Configuration
- LLM configuration for agent name
answer_synthesizerviallm.yaml.
Extension Points
- Modify
ANSWER_SYNTHESIZER_PROMPT. - Replace node in
build_graph()for custom synthesis.
Known Limitations
- No deterministic summarization guarantees without LLM configuration.
- No fallback response when LLM fails.
Related Code
packages/nl2sql/src/nl2sql/pipeline/nodes/answer_synthesizer/node.py