Skip to content
This repository was archived by the owner on Mar 29, 2026. It is now read-only.

fix: normalize OpenAI tool call arg keys and restore Snowflake session schema#1099

Open
lanzalibre wants to merge 2 commits into
vanna-ai:mainfrom
lanzalibre:fix/openai-tool-args-normalization-and-snowflake-schema
Open

fix: normalize OpenAI tool call arg keys and restore Snowflake session schema#1099
lanzalibre wants to merge 2 commits into
vanna-ai:mainfrom
lanzalibre:fix/openai-tool-args-normalization-and-snowflake-schema

Conversation

@lanzalibre

Copy link
Copy Markdown

Summary

Two runtime bugs found while integrating vanna2 with Snowflake and gpt-4o-mini:

  • OpenAI — trailing = in tool call argument keys: gpt-4o-mini occasionally emits Python-style kwarg notation in tool call JSON (e.g. {"question=": "value"} instead of {"question": "value"}), causing Pydantic validation to fail. Fixed by adding a _normalize_args() helper that strips trailing = from all argument dict keys, applied in both the streaming and non-streaming code paths of OpenAILlmService.

  • Snowflake — schema reset after USE DATABASE: Snowflake resets the active schema to the database default whenever USE DATABASE is executed. SnowflakeRunner was passing schema as a connector kwarg but then calling USE DATABASE inside run_sql(), silently discarding the configured schema for the duration of the query. Fixed by extracting schema from **kwargs at __init__ time and issuing an explicit USE SCHEMA after USE DATABASE in run_sql().

Test plan

  • Verify that tool calls from gpt-4o-mini with question= style keys are normalised and dispatched correctly
  • Verify that queries run against a Snowflake database with a non-default schema resolve objects correctly after the fix
  • Confirm no regression on existing OpenAI streaming / non-streaming tool call handling

gpt-4o-mini occasionally emits Python-style kwarg notation in tool call
JSON (e.g. {"question=": "value"} instead of {"question": "value"})
when function-call examples in the system prompt use keyword argument
syntax. This causes Pydantic validation to fail when the argument keys
do not match the expected field names.

Add a _normalize_args() helper that strips trailing '=' from all
argument dict keys, and apply it in both send_request() (non-streaming)
and stream_request() (streaming) tool call extraction paths.
Snowflake resets the active schema to the database default whenever
USE DATABASE is executed. SnowflakeRunner was passing schema as a
connector kwarg but then calling USE DATABASE inside run_sql(), which
silently discarded the schema for the rest of the session.

Extract schema from **kwargs at __init__ time and issue an explicit
USE SCHEMA after USE DATABASE in run_sql() to guarantee the correct
schema is always active.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant