Skip to content

Conversation

jatorre
Copy link
Contributor

@jatorre jatorre commented Oct 5, 2025

Summary

Adds function calling (tools) support for Snowflake Cortex REST API, enabling tool use with models like Claude 3.5 Sonnet.

Changes

Implementation (litellm/llms/snowflake/chat/transformation.py)

  • ✅ Add tools and tool_choice to supported OpenAI parameters
  • ✅ Implement request transformation: OpenAI → Snowflake tool_spec format
  • ✅ Implement response transformation: Snowflake content_list → OpenAI tool_calls
  • ✅ Add tool_choice transformation to Snowflake's array format

Testing

  • ✅ 7 unit tests for request/response transformations (tests/test_litellm/llms/snowflake/chat/test_snowflake_chat_transformation.py)
  • ✅ Integration test for Responses API with tool calling (tests/llm_translation/test_snowflake.py)
  • ✅ All tests passing

Technical Details

Request Transformations

Tools: OpenAI format → Snowflake tool_spec

# Before (OpenAI)
{"type": "function", "function": {"name": "get_weather", "parameters": {...}}}

# After (Snowflake)
{"tool_spec": {"type": "generic", "name": "get_weather", "input_schema": {...}}}

Tool Choice: OpenAI nested → Snowflake array

# Before (OpenAI)
{"type": "function", "function": {"name": "get_weather"}}

# After (Snowflake)
{"type": "tool", "name": ["get_weather"]}

Response Transformations

Parses Snowflake's unique format:

{
  "content_list": [
    {"type": "tool_use", "tool_use": {"tool_use_id": "...", "name": "...", "input": {...}}}
  ]
}

Converts to OpenAI format:

{
  "content": "...",
  "tool_calls": [{"id": "...", "type": "function", "function": {"name": "...", "arguments": "..."}}]
}

Verification

Tested with real Snowflake Cortex API (account: XXXXXX):

  • ✅ Tool calls with tool_choice (forced tool use)
  • ✅ Tool calls in auto mode (model decides)
  • ✅ Mixed text + tool call responses
  • ✅ Proper JSON argument serialization
  • ✅ Works with both completion() and responses() APIs

Example output:

Tool name: get_weather
Arguments: {"location": "Paris, France"}

Context

Test Plan

Unit tests (run automatically in CI):

pytest tests/test_litellm/llms/snowflake/chat/test_snowflake_chat_transformation.py -v

Integration test (requires Snowflake credentials - marked as skip):

# Set credentials first:
export SNOWFLAKE_JWT="your-jwt-token"
export SNOWFLAKE_ACCOUNT_ID="your-account-id"

# Then run:
pytest tests/llm_translation/test_snowflake.py::test_snowflake_tool_calling_responses_api -s

Breaking Changes

None - This is purely additive functionality.

🤖 Generated with Claude Code

…ST API

Add support for function calling (tools) with Snowflake Cortex models that support it (e.g., Claude 3.5 Sonnet).

Changes:
- Add 'tools' and 'tool_choice' to supported OpenAI parameters
- Implement request transformation: OpenAI function format → Snowflake tool_spec format
- Implement response transformation: Snowflake content_list with tool_use → OpenAI tool_calls
- Add tool_choice transformation: OpenAI nested format → Snowflake array format

Request transformation:
- Transform tools from nested {"type": "function", "function": {...}} to Snowflake's {"tool_spec": {"type": "generic", "name": "...", "input_schema": {...}}}
- Transform tool_choice from {"type": "function", "function": {"name": "..."}} to {"type": "tool", "name": ["..."]}

Response transformation:
- Parse Snowflake's content_list array containing tool_use objects
- Extract tool calls with tool_use_id, name, and input
- Convert to OpenAI's tool_calls format with proper JSON serialization

Testing:
- Add 7 unit tests covering request/response transformations
- Add integration test for Responses API with tool calling
- All tests passing

Fixes issue BerriAI#15218

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Copy link

vercel bot commented Oct 5, 2025

@jatorre is attempting to deploy a commit to the CLERKIEAI Team on Vercel.

A member of the Team first needs to authorize it.

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.

[Bug/Feature]: Snowflake Cortex now supports function calling but LiteLLM doesn't expose it
1 participant