Skip to content

Fix chat_with_SQL_3_ways.ipynb: SQLQuery breaks with OpenAIChatGenerator - #310

Open
mittalpk wants to merge 1 commit into
deepset-ai:mainfrom
mittalpk:fix/chat-with-sql-chatmessage-212
Open

Fix chat_with_SQL_3_ways.ipynb: SQLQuery breaks with OpenAIChatGenerator#310
mittalpk wants to merge 1 commit into
deepset-ai:mainfrom
mittalpk:fix/chat-with-sql-chatmessage-212

Conversation

@mittalpk

@mittalpk mittalpk commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #212.

llm.replies from OpenAIChatGenerator is List[ChatMessage], but SQLQuery.run() declared queries: List[str], so pipeline.connect("llm.replies", "sql_querier.queries") raised PipelineConnectError and the notebook couldn't even build.

SQLQuery now accepts List[Union[str, ChatMessage]] and extracts .text when given a ChatMessage. I used Union rather than switching the type outright because the notebook also calls SQLQuery.run() directly with plain strings in two other places (the standalone test call, and the function-calling variant later in the same notebook) — a ChatMessage-only signature would have fixed this pipeline while breaking those two.

Also found and fixed a second bug in the same notebook's conditional-routing section: ConditionalRouter's 'no_answer' in/not in replies[0] check operates on a ChatMessage object directly, which raises TypeError (ChatMessage isn't iterable) — needs .text. Its declared output_type: List[str] for the sql route was also inconsistent with the actual List[ChatMessage] value being routed.

Verified end-to-end against a real SQLite database (not just .connect() type-checking) with haystack-ai installed: the standalone string call, the ChatMessage pipeline call, the function-calling variant, and both ConditionalRouter branches (normal reply → sql, no_answer reply → go_to_fallback) all produce correct results with the patched notebook.

llm.replies from OpenAIChatGenerator is List[ChatMessage], but SQLQuery.run()
declared queries: List[str] -- pipeline.connect("llm.replies", "sql_querier.queries")
raised PipelineConnectError, so the notebook couldn't even build.

SQLQuery now accepts List[Union[str, ChatMessage]] and extracts .text when
given a ChatMessage, so it still works with the notebook's other two call
sites that pass plain strings directly (the standalone .run() call, and the
function-calling variant).

Also fixed a second bug in the same notebook's conditional-routing section:
the ConditionalRouter's 'no_answer' in/not in replies[0] check operated on a
ChatMessage object directly, which raises TypeError (ChatMessage isn't
iterable) -- needs .text. Its declared output_type: List[str] for the sql
route was also inconsistent with the actual List[ChatMessage] value being
routed.

Fixes deepset-ai#212.
@mittalpk
mittalpk requested a review from a team as a code owner August 5, 2026 19:35
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

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.

"Chat With Your SQL Database" should use OpenAIChatGenerator instead of OpenAIGenerator

1 participant