You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
importosfromlitellmimportRouterfrompydanticimportBaseModelclassRecipe(BaseModel):
name: strcook_time: strclassRecipeResponse(BaseModel):
data: Recipeos.environ["ANTHROPIC_API_KEY"] ="your-key-here"# Replace with your keysystem_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=""forchunkinresponse:
text=chunk.choices[0].delta.contentiftext:
final_response+=textprint("\nRaw Response:")
print(final_response)
Expected Behavior
The response should match the Pydantic model structure exactly:
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
Expected Behavior
The response should match the Pydantic model structure exactly:
Actual Behavior
The response includes an unexpected "values" wrapper:
Environment
Relevant log output
Are you a ML Ops Team?
No
What LiteLLM version are you on ?
1.62.1
Twitter / LinkedIn details
No response
The text was updated successfully, but these errors were encountered: