litellm - ✅(Solved) Fix [Bug]: Snowflake rejects role "tool" messages [1 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#23285Fetched 2026-04-08 00:37:41
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×3cross-referenced ×1

Error Message

litellm.exceptions.BadRequestError: SnowflakeException - {"message":"unknown role "tool"","error_code":"390142"}

Fix Action

Fixed

PR fix notes

PR #23279: fix(snowflake): transform messages for tool calling round trips

Description (problem / solution / changelog)

Snowflake's requires tool resultsto be in user messages with content_list containing tool_results blocks (not role: "tool"). Snowflake will throw an error: unknown role "tool" when provided with role: "tool" messages.

Relevant issues

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

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

This PR transforms OpenAI message format to Snowflake's expected format:

  • role: "tool" messages → role: "user" with content_list containing tool_results blocks
  • assistant messages with tool_callscontent_list with tool_use blocks
  • Multiple consecutive tool messages are combined into a single user message

Test plan

  • Unit tests added for message transformation
  • Tested against real Snowflake Cortex API

Changed files

  • litellm/llms/snowflake/chat/transformation.py (modified, +217/-1)
  • tests/test_litellm/llms/snowflake/chat/test_snowflake_chat_transformation.py (modified, +146/-0)

Code Example

import litellm

# Multi-turn conversation with tool results
messages = [
	{"role": "user", "content": "What's the weather in Paris?"},
	{
		"role": "assistant",
		"content": "I'll check that for you.",
		"tool_calls": [{
			"id": "call_123",
			"type": "function",
			"function": {
				"name": "get_weather",
				"arguments": '{"location": "Paris"}'
			}
		}]
	},
	{
		"role": "tool", # This fails - Snowflake doesn't accept this role
		"tool_call_id": "call_123",
		"content": "72°F and sunny"
	}
]

response = litellm.completion(
	model="snowflake/claude-3-5-sonnet",
	messages=messages,
	tools=[{
		"type": "function",
		"function": {
			"name": "get_weather",
			"description": "Get the current weather",
			"parameters": {
				"type": "object",
				"properties": {"location": {"type": "string"}},
				"required": ["location"]
			}
		}
	}],
	api_key="pat/your-token",
	account_id="your-account-id",
)

---

litellm.exceptions.BadRequestError: SnowflakeException - {"message":"unknown role \"tool\"","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 making multi-turn tool calling requests with Snowflake Cortex LLM API, sending tool results with role: "tool" (OpenAI format) causes Snowflake to return error: unknown role "tool".

Snowflake expects tool results as role: "user" messages with a content_list containing tool_results blocks (similar to Anthropic/Bedrock format), not the OpenAI role: "tool" format.

Expected: LiteLLM should transform role: "tool" messages to Snowflake's expected format with role: "user" and content_list containing tool_results.

Steps to Reproduce

import litellm

# Multi-turn conversation with tool results
messages = [
	{"role": "user", "content": "What's the weather in Paris?"},
	{
		"role": "assistant",
		"content": "I'll check that for you.",
		"tool_calls": [{
			"id": "call_123",
			"type": "function",
			"function": {
				"name": "get_weather",
				"arguments": '{"location": "Paris"}'
			}
		}]
	},
	{
		"role": "tool", # This fails - Snowflake doesn't accept this role
		"tool_call_id": "call_123",
		"content": "72°F and sunny"
	}
]

response = litellm.completion(
	model="snowflake/claude-3-5-sonnet",
	messages=messages,
	tools=[{
		"type": "function",
		"function": {
			"name": "get_weather",
			"description": "Get the current weather",
			"parameters": {
				"type": "object",
				"properties": {"location": {"type": "string"}},
				"required": ["location"]
			}
		}
	}],
	api_key="pat/your-token",
	account_id="your-account-id",
)

Relevant log output

litellm.exceptions.BadRequestError: SnowflakeException - {"message":"unknown role \"tool\"","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 fix the issue, we need to transform the role "tool" messages to Snowflake's expected format with role "user" and content_list containing tool_results.

Here are the steps:

  • Modify the message format for tool results to match Snowflake's expected format.
  • Update the litellm.completion call to use the modified message format.

Example Code

import litellm

# Multi-turn conversation with tool results
messages = [
    {"role": "user", "content": "What's the weather in Paris?"},
    {
        "role": "assistant",
        "content": "I'll check that for you.",
        "tool_calls": [{
            "id": "call_123",
            "type": "function",
            "function": {
                "name": "get_weather",
                "arguments": '{"location": "Paris"}'
            }
        }]
    },
    {
        "role": "user",  # Changed from "tool" to "user"
        "content": "72°F and sunny",
        "content_list": [{  # Added content_list with tool_results
            "tool_results": [
                {
                    "tool_call_id": "call_123",
                    "value": "72°F and sunny"
                }
            ]
        }]
    }
]

response = litellm.completion(
    model="snowflake/claude-3-5-sonnet",
    messages=messages,
    tools=[{
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get the current weather",
            "parameters": {
                "type": "object",
                "properties": {"location": {"type": "string"}},
                "required": ["location"]
            }
        }
    }],
    api_key="pat/your-token",
    account_id="your-account-id",
)

Verification

To verify that the fix worked, check the response from the litellm.completion call for a successful result. You can also check the Snowflake API logs to ensure that the request is being sent with the correct format.

Extra Tips

Make sure to update the litellm package to the latest version to ensure you have the latest fixes and features. Additionally, you can use the litellm documentation to learn more about the expected format for tool results and how to handle errors.

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