Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Unexpected "values" wrapper in JSON response with Pydantic models #9011

Open
preeteshjain opened this issue Mar 5, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@preeteshjain
Copy link

What happened?

When using LiteLLM with Pydantic models for response formatting, an unexpected "values" wrapper is added to the JSON response that isn't part of the defined schema.

The "values" key is not defined in any of the Pydantic models or mentioned in the documentation. This appears to be an unexpected wrapper being added during response processing. Seems to be happening only when stream=True

Reproduction Script

import os

from litellm import Router
from pydantic import BaseModel


class Recipe(BaseModel):
    name: str
    cook_time: str


class RecipeResponse(BaseModel):
    data: Recipe


os.environ["ANTHROPIC_API_KEY"] = "your-key-here"  # Replace with your key

system_prompt = "You are a helpful cooking assistant. Respond with recipe details in the specified format."
user_prompt = "Give me a quick recipe."

system_prompt = "You are a helpful cooking assistant. Respond with recipe details in the specified format."
user_prompt = "Give me a quick recipe."

router = Router(
    model_list=[
        {
            "model_name": "claude-sonnet",
            "litellm_params": {
                "model": "anthropic/claude-3-5-sonnet-latest",
                "api_key": os.environ["ANTHROPIC_API_KEY"],
            },
        }
    ],
)

response = router.completion(
    model="claude-sonnet",
    messages=[
        {"role": "system", "content": system_prompt},
        {"role": "user", "content": user_prompt},
    ],
    response_format=RecipeResponse,
    stream=True,
)

final_response = ""
for chunk in response:
    text = chunk.choices[0].delta.content
    if text:
        final_response += text

print("\nRaw Response:")
print(final_response)

Expected Behavior

The response should match the Pydantic model structure exactly:

{
    "data": {
        "name": "Quick Pasta",
        "cook_time": "15 minutes"
    }
}

Actual Behavior

The response includes an unexpected "values" wrapper:

{
    "values": {
        "data": {
            "name": "Quick Pasta",
            "cook_time": "15 minutes"
        }
    }
}

Environment

  • LiteLLM Version: 1.62.1
  • Python Version: 3.11.4

Relevant log output

Raw Response:
{"values": {"data":{"name":"3-Minute Microwave Scrambled Eggs","cook_time":"3 minutes"}}}

Are you a ML Ops Team?

No

What LiteLLM version are you on ?

1.62.1

Twitter / LinkedIn details

No response

@preeteshjain preeteshjain added the bug Something isn't working label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant