Melika Kheirieh commited on
Commit
3ef53b4
·
1 Parent(s): cc371b0

feat(api): expose executor result in NL2SQLResponse and return full result to UI

Browse files
Files changed (3) hide show
  1. README.md +144 -157
  2. app/routers/nl2sql.py +12 -0
  3. app/schemas.py +5 -4
README.md CHANGED
@@ -6,18 +6,18 @@ colorTo: blue
6
  sdk: docker
7
  pinned: false
8
  ---
9
-
10
  # 🧩 **NL2SQL Copilot — Natural-Language → Safe SQL**
11
  [![CI](https://github.com/melika-kheirieh/nl2sql-copilot/actions/workflows/ci.yml/badge.svg)](https://github.com/melika-kheirieh/nl2sql-copilot/actions/workflows/ci.yml)
12
  [![Docker](https://img.shields.io/badge/docker-ready-blue?logo=docker)](#)
13
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
14
 
 
15
  **Modular Text-to-SQL Copilot built with FastAPI & Pydantic-AI.**
16
- Generates *safe, verified, executable SQL* via a multi-stage agentic pipeline.
17
- Includes: self-repair, Spider benchmarks, Prometheus metrics, and a full demo UI.
18
 
19
- 🚀 **Live Demo (Hugging Face Space):**
20
- 👉 *(your HF link here)*
21
 
22
  ---
23
 
@@ -26,186 +26,190 @@ Includes: self-repair, Spider benchmarks, Prometheus metrics, and a full demo UI
26
  ```bash
27
  git clone https://github.com/melika-kheirieh/nl2sql-copilot
28
  cd nl2sql-copilot
29
- make setup # install deps
30
- make run # start API + UI
31
  ```
32
 
33
  Open:
34
- 👉 [http://localhost:8000](http://localhost:8000)
35
- 👉 [http://localhost:8000/docs](http://localhost:8000/docs) (Swagger UI)
 
36
 
37
  ---
38
 
39
  # **2) Demo (Gradio UI)**
40
 
41
- The live UI supports:
42
 
43
- * Uploading a SQLite database
44
  * Asking natural-language questions
45
  * Viewing generated SQL
46
- * Viewing execution results
47
- * Full trace per pipeline stage
48
- * Example queries for quick testing
49
- * No need to upload a DB for the demo (ships with a small example DB)
 
50
 
51
- Everything runs through the same agentic backend as the API.
52
 
53
  ---
54
 
55
- # **3) Architecture Overview**
56
 
57
  ```
58
  user query
59
 
60
- detector (ambiguous? dataset missing?)
61
- planner (task decomposition + schema reasoning)
62
  generator (SQL generation)
63
- safety (SELECT-only, no mutations)
64
- executor (SQLiteAdapter with sandboxing)
65
  verifier (semantic + execution checks)
66
  repair (minimal-diff SQL repair loop)
67
 
68
  final SQL + result + traces
69
  ```
70
 
71
- ### 🔧 Technical Stack
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
- * **FastAPI** HTTP API
74
- * **Pydantic-AI** — agentic stages
75
- * **SQLiteAdapter** — isolated DB execution
76
- * **Prometheus** — metrics
77
- * **Grafana** — dashboard
78
- * **Makefile + pytest + mypy** — dev workflow
 
 
79
 
80
- The entire pipeline is modular; each stage has a clean interface and can be swapped (e.g., planner or generator model).
81
 
82
  ---
83
 
84
- # **4) Key Features**
85
 
86
- ### ✔ Multi-Stage Agentic Pipeline
87
 
88
  Planner → Generator → Safety → Executor → Verifier → Repair.
89
 
 
 
 
 
90
  ### ✔ Safety by Design
91
 
92
- * Only `SELECT` queries allowed
93
  * Column/table validation
94
- * No multi-table hallucination
95
- * Deterministic schema preview
96
 
97
- ### ✔ Repair Loop
98
 
99
- Automatically fixes malformed or non-executable SQL using minimal edits and retries.
100
 
101
  ### ✔ Caching
102
 
103
- * TTL-based
104
- * Exact query deduplication
105
- * Miss/hit metrics
106
 
107
  ### ✔ Observability
108
 
109
  * Per-stage latency
110
  * Pipeline success ratio
111
  * Repair success rate
112
- * p95 latency
113
  * Cache hit ratio
 
114
  * Full Grafana dashboard
115
 
116
- ### ✔ Spider Benchmarks
117
-
118
- Reproducible evaluation on Spider (dev split).
119
- Comes with plotting utilities, histogram, latency per stage, and summary.json.
120
 
121
- ---
122
-
123
- باشه—الان **همین بخش Benchmarks که ساختم** را برایت
124
- **کاملاً آمادهٔ قرار گرفتن در README** می‌کنم:
125
-
126
- * با heading درست
127
- * با anchor مناسب
128
- * با ساختار کاملاً هم‌تراز با بقیهٔ README تو
129
- * با badge
130
- * بدون هیچ وابستگی اضافی
131
- * ۱۰۰٪ کپی‌ـ‌پیست مستقیم
132
-
133
- این نسخه **نهایی، آمادهٔ چسباندن** است:
134
 
135
  ---
136
 
137
- # 📊 Benchmarks (Spider dev, 20 samples)
138
 
139
- [![Benchmarks](https://img.shields.io/badge/Benchmarks-Spider%20dev-blue)](#benchmarks-spider-dev-20-samples)
140
 
141
- This copilot is evaluated on a 20-sample slice of the Spider **dev** split
142
- (focused on the `concert_singer` schema) using the production pipeline end-to-end.
143
 
144
  ### 🧮 Summary
145
 
146
- - **Total samples:** 20
147
- - **Successful runs:** 20 / 20 (**100%**)
148
- - **Exact Match (EM):** **0.10**
149
- - **Structural Match (SM):** **0.70**
150
- - **Execution Accuracy (ExecAcc):** **0.725**
151
 
152
- These results reflect a *production-oriented Text-to-SQL system*:
153
- the model optimizes for **valid, executable SQL**, not strict syntactic match.
154
 
155
  ---
156
 
157
  ### ⏱ Latency
158
 
159
- End-to-end pipeline time (all stages):
160
-
161
- - **Avg latency:** ~**8066 ms**
162
- - **p50 latency:** ~**9229 ms**
163
- - **p95 latency:** ~**14936 ms**
164
 
165
- Latency distribution is **bimodal**:
166
- 1) fast lookups,
167
- 2) multi-hop reasoning dominated by the planner stage.
168
-
169
- (See `latency_histogram.png` in the benchmark folder.)
170
 
171
  ---
172
 
173
- ### ⚙️ Per-Stage Latency (from Prometheus histograms)
174
 
175
- | Stage | Avg latency (ms) |
176
- |------------|------------------|
177
- | detector | ~1 |
178
- | planner | ~8360 |
179
- | generator | ~1645 |
180
- | safety | ~2 |
181
- | executor | ~1 |
182
- | verifier | ~1 |
183
- | repair | ~1200 |
184
 
185
- The **planner** is the dominant contributor—expected for a reasoning-heavy
186
- agentic pipeline. Safety/executor/verifier remain **single-digit ms**.
187
 
188
  ---
189
 
190
- ### ❌ Failure Modes (Why EM is low but ExecAcc is high)
191
 
192
- Even when EM=0, **SM و ExecAcc غالباً 1.0** هستند.
193
 
194
  Typical causes:
195
 
196
- - Column name capitalization differences
197
- - Different LIMIT usage
198
- - Different column order
199
- - Aliases not matching the gold query
200
- - Spider gold query being `EMPTY`, but the model (correctly) infers a SQL query
201
 
202
- In real systems, **execution correctness** matters more than literal match.
203
 
204
  ---
205
 
206
- ### 📂 Reproducibility
207
-
208
- Run the exact same benchmark:
209
 
210
  ```bash
211
  export SPIDER_ROOT="$PWD/data/spider"
@@ -215,12 +219,12 @@ PYTHONPATH=$PWD \
215
 
216
  PYTHONPATH=$PWD \
217
  python benchmarks/plot_results.py
218
- ````
219
 
220
- Artifacts stored under:
221
 
222
  ```
223
- benchmarks/results_pro/20251113-113600/
224
  summary.json
225
  eval.jsonl
226
  metrics_overview.png
@@ -229,11 +233,9 @@ benchmarks/results_pro/20251113-113600/
229
  errors_overview.png
230
  ```
231
 
232
- These plots are directly embedded into the README if needed.
233
-
234
  ---
235
 
236
- # **6) API Usage**
237
 
238
  ## 🔍 NL → SQL
239
 
@@ -247,29 +249,37 @@ curl -X POST "http://localhost:8000/api/v1/nl2sql" \
247
  }'
248
  ```
249
 
250
- Sample response:
251
 
252
  ```json
253
  {
254
  "ambiguous": false,
255
- "sql": "...",
256
- "rationale": "...",
257
- "result": [...],
 
 
 
 
 
 
 
 
258
  "traces": [
259
  {"stage": "detector", "duration_ms": 1},
260
- {"stage": "planner", "duration_ms": 8943},
261
- {"stage": "generator", "duration_ms": 1722},
262
- {"stage": "safety", "duration_ms": 2},
263
  {"stage": "executor", "duration_ms": 1},
264
  {"stage": "verifier", "duration_ms": 1},
265
- {"stage": "repair", "duration_ms": 522}
266
  ]
267
  }
268
  ```
269
 
270
  ---
271
 
272
- ## 📤 Upload SQLite DB
273
 
274
  ```bash
275
  curl -X POST "http://localhost:8000/api/v1/nl2sql/upload_db" \
@@ -277,15 +287,6 @@ curl -X POST "http://localhost:8000/api/v1/nl2sql/upload_db" \
277
  -F "file=@/path/to/db.sqlite"
278
  ```
279
 
280
- Response:
281
-
282
- ```json
283
- {
284
- "db_id": "9a21d49f-38d3-4ce0-a459-3688e02fd44a",
285
- "message": "Database uploaded successfully."
286
- }
287
- ```
288
-
289
  ---
290
 
291
  ## 📑 Schema Preview
@@ -297,57 +298,43 @@ curl "http://localhost:8000/api/v1/nl2sql/schema?db_id=<uuid>" \
297
 
298
  ---
299
 
300
- ## ⚙️ Environment Variables
301
 
302
- | Variable | Purpose |
303
- | ---------------------- | --------------------------------- |
304
- | `API_KEYS` | Comma-separated auth keys |
305
- | `DEV_MODE` | Enables strict ambiguity detector |
306
- | `NL2SQL_CACHE_TTL_SEC` | Cache TTL |
307
- | `NL2SQL_CACHE_MAX` | Cache size |
308
- | `SPIDER_ROOT` | Spider dataset path |
309
- | `USE_MOCK` | Skip DB execution |
 
310
 
311
- ---
312
-
313
- # **7) Future Work**
314
 
315
- The copilot is intentionally kept lean. Several scoped enhancements are planned:
316
 
317
- ### 1) Streaming SQL (SSE)
318
 
319
- Show partial SQL generation live.
320
 
321
  ### 2) Redis Distributed Cache
322
 
323
- Shared cache across replicas, eviction, warm-ups.
324
-
325
  ### 3) Multi-Model Planner/Generator
326
 
327
- Support OpenAI, vLLM, LLaMA, hybrid pipelines.
328
-
329
  ### 4) A/B Testing Framework
330
 
331
- Compare prompts/models with automated drift tracking.
332
-
333
  ### 5) Schema Embeddings
334
 
335
- Vector-based reasoning for table/column retrieval.
336
-
337
  ### 6) Nightly CI Benchmarks
338
 
339
- GitHub Actions run Spider → save plots → detect drift.
340
-
341
- ### 7) Stronger Diff-based Repair
342
-
343
- Trace-aware SQL recovery with history logging.
344
-
345
- ### 8) Deployment Template
346
 
347
- Helm chart / compose stack for production rollout.
348
 
349
  ---
350
 
351
- # **8) License**
352
 
353
  MIT License.
 
6
  sdk: docker
7
  pinned: false
8
  ---
 
9
  # 🧩 **NL2SQL Copilot — Natural-Language → Safe SQL**
10
  [![CI](https://github.com/melika-kheirieh/nl2sql-copilot/actions/workflows/ci.yml/badge.svg)](https://github.com/melika-kheirieh/nl2sql-copilot/actions/workflows/ci.yml)
11
  [![Docker](https://img.shields.io/badge/docker-ready-blue?logo=docker)](#)
12
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
13
 
14
+
15
  **Modular Text-to-SQL Copilot built with FastAPI & Pydantic-AI.**
16
+ Generates *safe, verified, executable SQL* through a multi-stage agentic pipeline.
17
+ Includes: schema introspection, self-repair, Spider benchmarks, Prometheus metrics, and a full demo UI.
18
 
19
+ 🚀 **Live Demo:**
20
+ 👉 **[https://huggingface.co/spaces/melika-kheirieh/nl2sql-copilot](https://huggingface.co/spaces/melika-kheirieh/nl2sql-copilot)**
21
 
22
  ---
23
 
 
26
  ```bash
27
  git clone https://github.com/melika-kheirieh/nl2sql-copilot
28
  cd nl2sql-copilot
29
+ make setup # install dependencies
30
+ make run # start API + Gradio UI
31
  ```
32
 
33
  Open:
34
+
35
+ * [http://localhost:8000](http://localhost:8000) (FastAPI Swagger UI)
36
+ * [http://localhost:7860](http://localhost:7860) (Gradio Demo)
37
 
38
  ---
39
 
40
  # **2) Demo (Gradio UI)**
41
 
42
+ The demo supports:
43
 
44
+ * Uploading any SQLite database
45
  * Asking natural-language questions
46
  * Viewing generated SQL
47
+ * Viewing query results
48
+ * Full multi-stage trace (detector planner → generator → safety → executor → verifier → repair)
49
+ * Per-stage timings
50
+ * Example queries
51
+ * And a default demo DB (no upload required)
52
 
53
+ Everything runs on the same backend as the API.
54
 
55
  ---
56
 
57
+ # **3) Agentic Architecture**
58
 
59
  ```
60
  user query
61
 
62
+ detector (ambiguity, missing info)
63
+ planner (schema reasoning + task decomposition)
64
  generator (SQL generation)
65
+ safety (SELECT-only validation)
66
+ executor (sandboxed DB execution)
67
  verifier (semantic + execution checks)
68
  repair (minimal-diff SQL repair loop)
69
 
70
  final SQL + result + traces
71
  ```
72
 
73
+ ### ⚙️ Tech Stack
74
+
75
+ * FastAPI
76
+ * Pydantic-AI
77
+ * SQLiteAdapter
78
+ * Prometheus + Grafana
79
+ * pytest + mypy + Makefile
80
+ * Gradio UI
81
+
82
+ The pipeline is fully modular: each stage has a clean, swappable interface.
83
+
84
+ ---
85
+
86
+ # **4) Evolution (Prototype → Copilot)**
87
+
88
+ This project is the **second-generation, production-grade** version of an earlier prototype:
89
+ 👉 [https://github.com/melika-kheirieh/nl2sql-copilot-prototype](https://github.com/melika-kheirieh/nl2sql-copilot-prototype)
90
+
91
+ The prototype explored single-step, prompt-based SQL generation.
92
+ The current version is a **complete architectural redesign**, adding:
93
 
94
+ * multi-stage agentic pipeline
95
+ * schema introspection
96
+ * safety guardrails
97
+ * self-repair loop
98
+ * caching
99
+ * observability
100
+ * Spider benchmarks
101
+ * multi-DB support with upload + TTL handling
102
 
103
+ This repository is the first **end-to-end, production-oriented** version.
104
 
105
  ---
106
 
107
+ # **5) Key Features**
108
 
109
+ ### ✔ Agentic Pipeline
110
 
111
  Planner → Generator → Safety → Executor → Verifier → Repair.
112
 
113
+ ### ✔ Schema-Aware
114
+
115
+ Automatic schema preview for any uploaded SQLite database.
116
+
117
  ### ✔ Safety by Design
118
 
119
+ * SELECT-only
120
  * Column/table validation
121
+ * No multi-statement SQL
122
+ * Prevents schema hallucination
123
 
124
+ ### ✔ Self-Repair
125
 
126
+ Automatic minimal-diff correction when SQL fails.
127
 
128
  ### ✔ Caching
129
 
130
+ TTL-based, with key = (db_id, normalized_query, schema_hash).
131
+ Hit/miss metrics included.
 
132
 
133
  ### ✔ Observability
134
 
135
  * Per-stage latency
136
  * Pipeline success ratio
137
  * Repair success rate
 
138
  * Cache hit ratio
139
+ * p95 latency
140
  * Full Grafana dashboard
141
 
142
+ ### ✔ Benchmarks
 
 
 
143
 
144
+ Reproducible Spider evaluation with plots + summary.
 
 
 
 
 
 
 
 
 
 
 
 
145
 
146
  ---
147
 
148
+ # **6) Benchmarks (Spider dev, 20 samples)**
149
 
150
+ [![Benchmarks](https://img.shields.io/badge/Benchmarks-Spider%20dev-blue)](#benchmarks)
151
 
152
+ Evaluated on a curated 20-sample subset of the Spider **dev** split
153
+ (focused on `concert_singer`), using the full production pipeline.
154
 
155
  ### 🧮 Summary
156
 
157
+ * **Total samples:** 20
158
+ * **Successful runs:** 20/20 (**100%**)
159
+ * **Exact Match (EM):** **0.10**
160
+ * **Structural Match (SM):** **0.70**
161
+ * **Execution Accuracy:** **0.725**
162
 
163
+ This reflects a *production-oriented* NL2SQL system:
164
+ the model optimizes for **executable SQL**, not literal gold-string alignment.
165
 
166
  ---
167
 
168
  ### ⏱ Latency
169
 
170
+ * **Avg latency:** ~**8066 ms**
171
+ * **p50:** ~**9229 ms**
172
+ * **p95:** ~**14936 ms**
 
 
173
 
174
+ Latency is **bimodal**:
175
+ simple queries → fast, reasoning-heavy queries → planner-dominated.
 
 
 
176
 
177
  ---
178
 
179
+ ### ⚙️ Per-Stage Latency
180
 
181
+ | Stage | Avg latency (ms) |
182
+ | --------- | ---------------- |
183
+ | detector | ~1 |
184
+ | planner | ~8360 |
185
+ | generator | ~1645 |
186
+ | safety | ~2 |
187
+ | executor | ~1 |
188
+ | verifier | ~1 |
189
+ | repair | ~1200 |
190
 
191
+ Planner is the main bottleneck (expected for schema-level reasoning).
192
+ Safety/executor/verifier stay **single-digit ms**.
193
 
194
  ---
195
 
196
+ ### ❌ Failure Modes (Why EM is low)
197
 
198
+ Even when EM = 0, **SM and ExecAcc are often 1.0**.
199
 
200
  Typical causes:
201
 
202
+ * Capitalization differences (`Age` vs `age`)
203
+ * Different column ordering
204
+ * LIMIT differences
205
+ * Alias mismatch
206
+ * Gold SQL is `EMPTY` but the model infers a valid SQL
207
 
208
+ In real-world systems, **execution correctness matters more than exact string match**.
209
 
210
  ---
211
 
212
+ ### 📂 Reproducing the Benchmark
 
 
213
 
214
  ```bash
215
  export SPIDER_ROOT="$PWD/data/spider"
 
219
 
220
  PYTHONPATH=$PWD \
221
  python benchmarks/plot_results.py
222
+ ```
223
 
224
+ Artifacts saved under:
225
 
226
  ```
227
+ benchmarks/results_pro/<timestamp>/
228
  summary.json
229
  eval.jsonl
230
  metrics_overview.png
 
233
  errors_overview.png
234
  ```
235
 
 
 
236
  ---
237
 
238
+ # **7) API Usage**
239
 
240
  ## 🔍 NL → SQL
241
 
 
249
  }'
250
  ```
251
 
252
+ ### ✔ Sample Response (accurate)
253
 
254
  ```json
255
  {
256
  "ambiguous": false,
257
+ "sql": "SELECT ...",
258
+ "rationale": "Explanation of why this SQL was generated.",
259
+ "result": {
260
+ "rows": 5,
261
+ "columns": ["CustomerId", "Total"],
262
+ "rows_data": [
263
+ [1, 39.6],
264
+ [2, 38.7],
265
+ [3, 35.4]
266
+ ]
267
+ },
268
  "traces": [
269
  {"stage": "detector", "duration_ms": 1},
270
+ {"stage": "planner", "duration_ms": 8943},
271
+ {"stage": "generator","duration_ms": 1722},
272
+ {"stage": "safety", "duration_ms": 2},
273
  {"stage": "executor", "duration_ms": 1},
274
  {"stage": "verifier", "duration_ms": 1},
275
+ {"stage": "repair", "duration_ms": 522}
276
  ]
277
  }
278
  ```
279
 
280
  ---
281
 
282
+ ## 📁 Upload a SQLite DB
283
 
284
  ```bash
285
  curl -X POST "http://localhost:8000/api/v1/nl2sql/upload_db" \
 
287
  -F "file=@/path/to/db.sqlite"
288
  ```
289
 
 
 
 
 
 
 
 
 
 
290
  ---
291
 
292
  ## 📑 Schema Preview
 
298
 
299
  ---
300
 
301
+ # **8) Environment Variables**
302
 
303
+ | Variable | Purpose |
304
+ | ---------------------- | ---------------------------------------- |
305
+ | `API_KEYS` | Comma-separated list of backend API keys |
306
+ | `API_KEY` | Used by Gradio UI to call the backend |
307
+ | `DEV_MODE` | Enables strict ambiguity detection |
308
+ | `NL2SQL_CACHE_TTL_SEC` | Cache TTL |
309
+ | `NL2SQL_CACHE_MAX` | Max cache entries |
310
+ | `SPIDER_ROOT` | Path to Spider dataset |
311
+ | `USE_MOCK` | Skip execution (for testing) |
312
 
313
+ > Gradio uses `API_KEY` → backend expects it as `X-API-Key`.
314
+ > Backend accepts multiple keys via `API_KEYS`.
 
315
 
316
+ ---
317
 
318
+ # **9) Future Work**
319
 
320
+ ### 1) Streaming SQL Generation (SSE)
321
 
322
  ### 2) Redis Distributed Cache
323
 
 
 
324
  ### 3) Multi-Model Planner/Generator
325
 
 
 
326
  ### 4) A/B Testing Framework
327
 
 
 
328
  ### 5) Schema Embeddings
329
 
 
 
330
  ### 6) Nightly CI Benchmarks
331
 
332
+ ### 7) Advanced Repair (diff-based)
 
 
 
 
 
 
333
 
334
+ ### 8) Helm / Compose Deployment Template
335
 
336
  ---
337
 
338
+ # **10) License**
339
 
340
  MIT License.
app/routers/nl2sql.py CHANGED
@@ -384,12 +384,24 @@ def nl2sql_handler(
384
 
385
  # Success path → 200 (coerce/standardize traces for API)
386
  traces = [_round_trace(t) for t in (result.traces or [])]
 
 
 
 
 
 
 
 
 
 
387
  payload = NL2SQLResponse(
388
  ambiguous=False,
389
  sql=result.sql,
390
  rationale=result.rationale,
391
  traces=traces,
 
392
  )
 
393
  # store in cache
394
  _CACHE[ck] = (time.time(), cast(Dict[str, Any], payload.model_dump()))
395
  return payload
 
384
 
385
  # Success path → 200 (coerce/standardize traces for API)
386
  traces = [_round_trace(t) for t in (result.traces or [])]
387
+
388
+ # Normalize execution result (if executor attached one)
389
+ response_result: Dict[str, Any] = {}
390
+ raw_result = getattr(result, "result", None)
391
+ if raw_result is not None:
392
+ if isinstance(raw_result, dict):
393
+ response_result = raw_result
394
+ else:
395
+ response_result = cast(Dict[str, Any], _to_dict(raw_result))
396
+
397
  payload = NL2SQLResponse(
398
  ambiguous=False,
399
  sql=result.sql,
400
  rationale=result.rationale,
401
  traces=traces,
402
+ result=response_result,
403
  )
404
+
405
  # store in cache
406
  _CACHE[ck] = (time.time(), cast(Dict[str, Any], payload.model_dump()))
407
  return payload
app/schemas.py CHANGED
@@ -1,5 +1,5 @@
1
- from pydantic import BaseModel, Field
2
- from typing import List, Optional, Any, Dict, Mapping, Sequence
3
 
4
 
5
  class NL2SQLRequest(BaseModel):
@@ -21,10 +21,11 @@ class TraceModel(BaseModel):
21
 
22
 
23
  class NL2SQLResponse(BaseModel):
24
- ambiguous: bool = False
25
  sql: Optional[str] = None
26
  rationale: Optional[str] = None
27
- traces: Sequence[TraceModel | Mapping[str, Any]] = Field(default_factory=list)
 
28
 
29
 
30
  class ClarifyResponse(BaseModel):
 
1
+ from pydantic import BaseModel
2
+ from typing import List, Optional, Any, Dict
3
 
4
 
5
  class NL2SQLRequest(BaseModel):
 
21
 
22
 
23
  class NL2SQLResponse(BaseModel):
24
+ ambiguous: bool
25
  sql: Optional[str] = None
26
  rationale: Optional[str] = None
27
+ traces: List[Dict[str, Any]] = []
28
+ result: Dict[str, Any] = {}
29
 
30
 
31
  class ClarifyResponse(BaseModel):