RefinerNode
Overview
- Generates corrective feedback for planning failures using an LLM.
- Exists to improve planner outputs in retry loops.
- Sits between
retry_handlerandASTPlannerNodein the SQL agent subgraph. - Class:
RefinerNode - Source:
packages/nl2sql/src/nl2sql/pipeline/nodes/refiner/node.py
Responsibilities
- Summarize planning errors and reasoning context.
- Invoke LLM to generate feedback.
- Emit
PLAN_FEEDBACKwarnings to drive retry.
Position in Execution Graph
Upstream:
- retry_handler
Downstream:
- ASTPlannerNode
Trigger conditions: - Executed when retry handler routes to refinement.
flowchart LR
RetryHandler[retry_handler] --> Refiner[RefinerNode] --> Planner[ASTPlannerNode]
Inputs
From SubgraphExecutionState:
errorsreasoningrelevant_tablesast_planner_response.plan(optional)sub_query.intent
Validation performed:
- If no LLM configured, emits
MISSING_LLM.
Outputs
Mutations to SubgraphExecutionState:
refiner_response(RefinerResponse)errors(includesPLAN_FEEDBACKwarning)reasoning
Side effects:
- LLM invocation.
Internal Flow (Step-by-Step)
- If no LLM configured, emit
MISSING_LLMand stop. - Serialize relevant tables and failed plan.
- Build error and reasoning strings.
- Invoke LLM with refinement prompt.
- Emit
PLAN_FEEDBACKwarning and returnRefinerResponse. - On exception, emit
REFINER_FAILED.
Contracts & Interfaces
Implements a LangGraph node callable:
Key contracts:
RefinerResponsePipelineError(PLAN_FEEDBACK,MISSING_LLM,REFINER_FAILED)
Determinism Guarantees
- Non‑deterministic unless LLM configured deterministically.
Error Handling
Emits PipelineError with:
MISSING_LLMPLAN_FEEDBACK(warning)REFINER_FAILED
Logs failures via logger.error.
Retry + Idempotency
- No internal retry logic.
- Idempotency depends on LLM determinism.
Performance Characteristics
- LLM call dominates latency.
- Serialization of inputs is in‑memory.
Observability
- Logger:
refiner - Adds reasoning entries with feedback content.
Configuration
- LLM configuration for agent name
refinerviallm.yaml.
Extension Points
- Modify
REFINER_PROMPTfor different refinement behavior. - Replace node in
build_sql_agent_graph()for alternate retry strategies.
Known Limitations
- No fallback if LLM unavailable.
- Feedback quality depends on LLM and prompt.
Related Code
packages/nl2sql/src/nl2sql/pipeline/nodes/refiner/node.py