Repository navigation
fix(chat): repair a SQL statement the database rejects, once - #92
Conversation
Artifacts got one repair attempt for a rejected statement in PR #90; the chat had none, so on ClickHouse 22.1 every dialect slip reached the user as "Pipeline error". On the GONAC server most chat questions failed that way: a Spanish alias with an unquoted ñ, an alias that shadows the column it aggregates, arithmetic between window functions, a String date compared with a Date, a conversion applied to a column that already is a Date. - sql_repair.py: the repair, its dialect notes and error hints move out of routers/artifact.py and are shared by the chat and the artifacts. Three hints are added for the GONAC errors whose text does not name the fix. Connection, timeout and authentication errors are not sent to the model: no rewrite of the statement fixes them. - routers/query.py: a rejected chat statement gets one repair, recorded as the sql_repair phase; a statement that fails twice keeps its second error, and the chat shows the statement that ran. - prompts/clickhouse.py: ASCII-only aliases, no alias that shadows the column it reads, window arithmetic in an outer query. Prose, no worked SQL, because an example in a rules block acts as a template. Flash mode generates and runs its own SQL inside ask-intent-resolution and is not covered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measurement on the GONAC PoC server (2026-10-27)Same 12 Spanish questions, workspace
First-statement errors, by kind:
The remaining failures are mostly not SQL. The Deployed to the PoC server as |
Same 12 questions on
|
Brings the artifact delete of PR #91 into this stacked branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
Artifacts repair a rejected SQL statement once (#90). The chat did not: on ClickHouse 22.1 (GONAC PoC server) every dialect slip reached the user as
Pipeline error. Errors seen in the server log on 2026-10-27, from the chat and artifacts:SYNTAX_ERROR,Unrecognized token: '\xc3'(x3)ñILLEGAL_AGGREGATION(x2)SUM(x) AS x, then anotherSUM(x)ILLEGAL_TYPE_OF_ARGUMENT(x2)toDateOrNull(order_date) AS order_dateon a column that already is a DateNO_COMMON_TYPE(x2)UNKNOWN_IDENTIFIER(x3)UNKNOWN_TABLE(x1)Change
sql_repair.py(new): the repair, its dialect notes and its error hints move out ofrouters/artifact.py, shared by chat and artifacts. Three hints added for the errors whose text does not name the fix (non-ASCII alias, String vs Date, conversion on a Date). Connection, timeout and authentication errors are not sent to the model.routers/query.py: a rejected chat statement gets one repair (token phasesql_repair). A statement that fails twice keeps its second error; the chat shows the statement that ran.prompts/clickhouse.py: rule 7 asks for ASCII-only aliases; new rules 14 (no alias that shadows the column it reads) and 15 (window arithmetic in an outer query). Prose only: an example in a rules block acts as a template.Not covered: Flash mode generates and runs its own SQL inside
ask-intent-resolution.Tests
test_chat_sql_repair.py: 16 tests (one repair and its result, no repair when the statement runs, no second repair, original error when no usable repair, unreachable database not sent to the model, the three new hints with the real error texts, which errors are repairable). Checked against mutants without the chat repair and without the new hints: they fail.test_artifact_sub_sql_repair.pyandtest_artifact_env.pypass unchanged apart from patchingSettingsCachewhere the repair now lives.Measurement on the GONAC server (before/after on the same questions) to follow in a comment.
🤖 Generated with Claude Code