Skip to content

feat(datafabric): add choice-set awareness to NL-to-SQL pipeline - #1057

Draft
UIPath-Harshit wants to merge 3 commits into
mainfrom
feat/choiceset-awareness
Draft

feat(datafabric): add choice-set awareness to NL-to-SQL pipeline#1057
UIPath-Harshit wants to merge 3 commits into
mainfrom
feat/choiceset-awareness

Conversation

@UIPath-Harshit

@UIPath-Harshit UIPath-Harshit commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds choice-set field awareness across the NL-to-SQL pipeline — from schema resolution through prompt generation to result post-processing
  • Resolves DS-8647: Handle queries involving choice sets

Problem

The NL-to-SQL pipeline had zero choice-set awareness. Choice-set fields (CHOICE_SET_SINGLE / CHOICE_SET_MULTIPLE) were rendered as raw SQL types (int / nvarchar) with:

  • No value metadata (LLM had no idea Critical=0, High=1, etc.)
  • No label-to-NumberId mapping in prompts
  • No choice-set-specific SQL patterns in constraints
  • No result post-processing to translate NumberIds back to labels
  • No cross-entity shared choice-set join hints

This caused incorrect SQL generation (e.g. WHERE Priority = 4 instead of Priority = 0 for "Critical") and unintelligible results ("priority 0" instead of "Critical").

Changes

File What
models.py ChoiceSetValueSchema, choiceset_id/choiceset_values on FieldSchema, is_choice_set property, is_numeric returns False for CS fields, shared_choicesets/choiceset_label_maps on SQLContext
datafabric_prompt_builder.py Fetch CS values via SDK during schema resolution, bridge choiceSetId alias mismatch via entity GET, render value mappings inline + dedicated section, emit cross-entity shared CS join hints
datafabric_subgraph.py QueryExecutor enriches results with _label suffix columns for CS NumberIds
datafabric_prompts.py Rule 12: "Choice-set fields use integer NumberIds"
prompts/v1.py CHOICE-SET FIELDS section in VALUE RESOLUTION step, EMPTY_RESULT recovery references CS mappings

Test plan

  • 117 existing unit tests pass with zero regressions
  • 15/15 comprehensive gap verification tests pass (8 deterministic SDK/prompt/model + 7 live NL-to-SQL agent queries)
  • Tested against 3 live entities on alpha: SupportTickets (3 CS fields), TicketComments (shared CS + FK), AgentShifts (shared CS, no FK)
  • Run full BIRD eval suite to confirm no regression on non-CS queries

10 Gaps Addressed

Gap Before After
1: CS value in WHERE Priority = 4 (wrong) Priority = 0 (correct)
2: FieldSchema model No CS awareness is_choice_set, values, mapping_str
3: Label→NumberId No mapping in prompt Critical=0, High=1... inline
4: SQL constraints Zero CS mentions Rule 12 added
5: Query patterns String quotes on INT CS filter pattern with NumberId
6: Result labels "priority 0" Priority_label: 'Critical'
7: Cross-entity CS Worked by accident Semantic + labels
8: FK join + CS filter Lucky guess Consistent correct IDs
9: Explicit string join Already worked No regression
10: Pure CS join Refused to join Generates LEFT JOIN with shared CS hint

🤖 Generated with Claude Code

UIPath-Harshit and others added 3 commits August 12, 2026 10:54
The NL-to-SQL pipeline had zero choice-set awareness — choice-set fields
were rendered as raw SQL types (int/nvarchar) with no value metadata, no
label-to-NumberId mapping, and no filtering guidance. This caused incorrect
SQL generation (e.g. WHERE Priority = 4 instead of Priority = 0 for
"Critical") and unintelligible results (raw NumberIds instead of labels).

Changes:
- models.py: Add ChoiceSetValueSchema, choiceset_id/choiceset_values to
  FieldSchema, is_choice_set property, fix is_numeric to return False for
  CS fields, add shared_choicesets/choiceset_label_maps to SQLContext
- datafabric_prompt_builder.py: Fetch choice-set values via SDK during
  schema resolution, bridge choiceSetId alias mismatch via entity GET,
  render value mappings inline in schema table and as dedicated section,
  emit cross-entity shared choice-set join hints
- datafabric_subgraph.py: Enrich query results with _label suffix columns
  for choice-set NumberIds, pass label maps through QueryExecutor
- datafabric_prompts.py: Add Rule 12 for choice-set integer NumberId usage
- prompts/v1.py: Add CHOICE-SET FIELDS guidance in VALUE RESOLUTION step,
  update EMPTY_RESULT error recovery to reference CS mappings

Verified: 15/15 tests pass (8 deterministic + 7 live NL-to-SQL) covering
all 10 identified choice-set gaps across SDK, prompt, model, and agent
layers. 117 existing unit tests pass with zero regressions.

Ref: DS-8647

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant