[BUG]SQL Parsing Fails for Valid LLM Outputs with Non-Standard JSON Structure
@xuwei-fit2cloud is already working on this.
Since Jan 2, 2026.
- Dominant language
- JavaScript
- Stars
- 6.8k
- Forks
- 882
- Avg merge
- 4h 37m
- Merged PRs (30d)
- 32
Description
SQLBot Version
1.5.1
Run Mode
Is it running in a Docker container or running from source code?
Docker
Describe the bug
When using local or open-source LLMs (e.g. Qwen2.5-32B, Qwen3-32B, LLaMA 3.x), SQLBot fails to parse valid SQL generated by the model and raises the error:
Cannot parse sql from answer
This happens even though the LLM output contains a correct and executable SQL statement.
The failure is caused by SQLBot relying on a strict JSON schema for parsing, while many LLMs return SQL in alternative but reasonable formats.
To Reproduce
Deploy SQLBot 1.5.1 using Docker
Configure a local LLM (Qwen2.5-32B / Qwen3-32B / LLaMA 3.x) via Ollama or vLLM
Ask a simple SQL question (e.g. daily aggregation query)
Let the LLM generate SQL
Observe the error:Cannot parse sql from answer
Example LLM output that is rejected:{
"query": "SELECT SUM(chulu_guoshu) FROM example_table WHERE DATE(insert_time) = '2025-12-31'"
}
Expected behavior
SQLBot should successfully extract and execute SQL as long as the generated SQL is valid, including cases such as:
{ "query": "SELECT ..." }
{ "sql": "SELECT ..." }
Nested JSON containing SQL
Plain SQL strings starting with SELECT
The system should not require a single rigid JSON structure for SQL parsing.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
SQLBot rejects valid SQL outputs that do not strictly match the expected JSON schema and throws:Cannot parse sql from answer
Additional context
This is not an SQL generation issue — the SQL itself is correct
The problem occurs at the SQL parsing stage only
Cloud models tend to follow the expected format, but local/open-source models do not
This significantly limits SQLBot’s usability with local LLM deployments
A more tolerant SQL extraction mechanism or fallback for raw SQL would greatly improve compatibility.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.