litellm - ✅(Solved) Fix [Bug]: Snowflake tool_choice string values rejected [2 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#23284Fetched 2026-04-08 00:37:43
View on GitHub
Comments
0
Participants
1
Timeline
7
Reactions
0
Participants
Timeline (top)
cross-referenced ×2labeled ×2referenced ×2closed ×1

Error Message

litellm.exceptions.BadRequestError: SnowflakeException - {"message":"invalid payload","error_code":"390142"}

Fix Action

Fixed

PR fix notes

PR #23268: fix(snowflake): transform tool_choice string to object format

Description (problem / solution / changelog)

Snowflake's Cortex API documentation is pretty inconsistent, but it requires tool_choice to be an object, not a string. For example, {"type": "auto"} instead of "auto".

Relevant issues

Fixes https://github.com/BerriAI/litellm/issues/23284

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🐛 Bug Fix

Changes

  • Updated litellm/llms/snowflake/chat/transformation.py to transform string values for tool_choice to object format

Test plan

  • Unit tests updated and passing
  • Tested against real Snowflake Cortex API with tool calls

Ref: https://docs.snowflake.com/en/developer-guide/snowflake-rest-api/reference/cortex-inference#post--api-v2-cortex-inference-complete-req-body-schema

<img width="796" height="640" alt="image" src="https://github.com/user-attachments/assets/58684c09-347d-4953-b261-ceeb58073f8d" />

Changed files

  • litellm/llms/openai_like/providers.json (modified, +7/-0)
  • litellm/llms/snowflake/chat/transformation.py (modified, +11/-10)
  • litellm/model_prices_and_context_window_backup.json (modified, +189/-0)
  • litellm/types/router.py (modified, +19/-112)
  • litellm/types/utils.py (modified, +1/-0)
  • model_prices_and_context_window.json (modified, +189/-0)
  • tests/test_litellm/llms/openai_like/test_charity_engine.py (added, +101/-0)
  • tests/test_litellm/llms/snowflake/chat/test_snowflake_chat_transformation.py (modified, +6/-2)
  • tests/test_litellm/test_litellm_params_reserved_keys.py (added, +92/-0)

PR #23318: fix(snowflake): transform string tool_choice to object format

Description (problem / solution / changelog)

Summary

Fixes #23284

Snowflake's Cortex LLM API (like Anthropic's Messages API) requires tool_choice as an object with a "type" field, not as a bare string. Passing tool_choice="auto" (or "required"/"none") results in Snowflake error 390142 "invalid payload".

Root cause

The _transform_tool_choice method in SnowflakeConfig was passing string tool_choice values through unchanged. However, Snowflake's API follows the Anthropic convention where tool_choice must be an object like {"type": "auto"}.

LiteLLM's own Anthropic handler (AnthropicConfig._map_tool_choice) already correctly transforms strings to objects -- the Snowflake handler was missing the same transformation.

Fix

Transform OpenAI string tool_choice values to Snowflake's object format:

OpenAI (string)Snowflake (object)
"auto"{"type": "auto"}
"required"{"type": "any"}
"none"{"type": "none"}

The "required" -> "any" mapping follows the same convention used by Anthropic/Snowflake (the model must use at least one tool).

The existing dict-to-dict transformation for specific function tool choices remains unchanged.

Tests updated

Updated test_transform_request_with_string_tool_choice to verify the new object format output instead of passthrough.

Test plan

  • Verify tool_choice="auto" is transformed to {"type": "auto"}
  • Verify tool_choice="required" is transformed to {"type": "any"}
  • Verify tool_choice="none" is transformed to {"type": "none"}
  • Verify dict tool_choice (specific function) still works
  • Verify requests without tool_choice are unaffected

Changed files

  • litellm/llms/snowflake/chat/transformation.py (modified, +22/-7)
  • tests/test_litellm/llms/snowflake/chat/test_snowflake_chat_transformation.py (modified, +14/-5)

Code Example

import litellm

response = litellm.completion(
	model="snowflake/claude-3-5-sonnet",
	messages=[{"role": "user", "content": "What's the weather in Paris?"}],
	tools=[{
		"type": "function",
		"function": {
			"name": "get_weather",
			"description": "Get the current weather",
			"parameters": {
				"type": "object",
				"properties": {
					"location": {"type": "string"}
				},
				"required": ["location"]
			}
		}
	}],
	tool_choice="auto", # This fails
	api_key="pat/your-token",
	account_id="your-account-id",
)

---

litellm.exceptions.BadRequestError: SnowflakeException - {"message":"invalid payload","error_code":"390142"}
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

When using Snowflake Cortex LLM API with tool_choice="auto" (or other string values like "required", "none"), Snowflake returns error 390142 "invalid payload".

Snowflake expects tool_choice as an object format {"type": "auto"}, not a string "auto". LiteLLM was passing the string through unchanged.

Expected: tool_choice="auto" should be transformed to {"type": "auto"} before sending to Snowflake.

Steps to Reproduce

import litellm

response = litellm.completion(
	model="snowflake/claude-3-5-sonnet",
	messages=[{"role": "user", "content": "What's the weather in Paris?"}],
	tools=[{
		"type": "function",
		"function": {
			"name": "get_weather",
			"description": "Get the current weather",
			"parameters": {
				"type": "object",
				"properties": {
					"location": {"type": "string"}
				},
				"required": ["location"]
			}
		}
	}],
	tool_choice="auto", # This fails
	api_key="pat/your-token",
	account_id="your-account-id",
)

Relevant log output

litellm.exceptions.BadRequestError: SnowflakeException - {"message":"invalid payload","error_code":"390142"}

What part of LiteLLM is this about?

SDK (litellm Python package)

What LiteLLM version are you on ?

v1.63.2

Twitter / LinkedIn details

No response

extent analysis

Fix Plan

To resolve the issue, we need to modify the litellm library to transform the tool_choice parameter from a string to an object format before sending it to Snowflake.

Here are the steps to fix the issue:

  • Modify the completion function in the litellm library to accept an object format for tool_choice.
  • Add a conditional statement to transform the tool_choice string to an object format if it's not already an object.

Example code:

# In litellm library
def completion(..., tool_choice, ...):
    if isinstance(tool_choice, str):
        tool_choice = {"type": tool_choice}
    # Rest of the function remains the same
    ...

Alternatively, you can also modify your code to pass the tool_choice as an object:

response = litellm.completion(
    ...
    tool_choice={"type": "auto"},
    ...
)

Verification

To verify that the fix worked, run your code with the modified tool_choice parameter and check that the response from Snowflake is successful.

Extra Tips

Make sure to update the litellm library to the latest version after the fix is released. Also, always check the documentation for the latest parameter formats and requirements for the Snowflake API.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - ✅(Solved) Fix [Bug]: Snowflake tool_choice string values rejected [2 pull requests, 1 participants]