Skip to content

SQL base: EXPLAIN-exhausted query returns valid=True; isValid parsing crashes on real JSON bool #1601

Description

@dsapandora

Description

While building the graph base in #1584, @asclearuc noted that the SQL base packages/ai/src/ai/common/database/db_instance_base.py carries two issues the graph copy already fixes:

  1. _buildSQLQuery returns valid: True after EXPLAIN exhaustion. When EXPLAIN rejects a generated query on every attempt, it returns the last result with isValid still 'true', so get_sql returns {sql, valid: True} and get_data then executes a statement the database already refused, surfacing only an unhelpful "Query execution failed". The graph base sets isValid=False + error on exhaustion (see feat(nodes, ai): add graph base class; make FalkorDB a real graph node #1584, commits 6419df02 / 87e49c3d); the SQL base should do the same.

  2. isValid parsing crashes on a real JSON boolean. db_instance_base does result.get('isValid', '').lower() == 'true' in three places, which raises AttributeError the moment the LLM returns a real JSON boolean (true) instead of the string 'true'. It should go through ai.common.utils.parse_bool (the graph base already switched to it and dropped its local parse_is_valid).

Steps to Reproduce

  1. (issue 1) Point a SQL node (e.g. db_postgres) at a schema and ask a question whose generated query EXPLAIN keeps rejecting → get_sql returns valid: True and get_data executes it, failing with a generic error instead of surfacing the validation error.
  2. (issue 2) Have the LLM answer {"isValid": true, ...} (real bool) → .lower() raises AttributeError.

Expected vs Actual Behavior

  • Expected: exhausted validation returns valid: False plus the EXPLAIN error; a real-JSON-bool isValid parses without crashing.
  • Actual: valid: True + blind execution of a rejected query; AttributeError on a JSON-bool isValid.

Severity

Medium — affects the SQL nodes (db_postgres, db_mysql, db_clickhouse, db_arango): degraded error UX plus a crash path on a plausible LLM output.

Platform

  • Windows
  • macOS
  • Linux

Version / Environment

develop, after #1584. Reference fix already in the graph base — port it to db_instance_base.py.

Metadata

Metadata

Assignees

Labels

P2-mediumMedium priorityaiAI/ML modulesbugSomething isn't workingnodesPipeline nodes

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions