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

[Feature]: json_schema support for Anthropic #6741

Closed
Seluj78 opened this issue Nov 14, 2024 · 6 comments · Fixed by #6748
Closed

[Feature]: json_schema support for Anthropic #6741

Seluj78 opened this issue Nov 14, 2024 · 6 comments · Fixed by #6748
Labels
enhancement New feature or request

Comments

@Seluj78
Copy link

Seluj78 commented Nov 14, 2024

The Feature

Currently, you only support a small amount of json format models :
https://docs.litellm.ai/docs/completion/json_mode

Motivation, pitch

I would need to be able to do the same with Anthropic models, without having to specify to the model how to output in json

Twitter / LinkedIn details

No response

@Seluj78 Seluj78 added the enhancement New feature or request label Nov 14, 2024
@Seluj78
Copy link
Author

Seluj78 commented Nov 14, 2024

If I am not mistaken, using the Python SDK, I can see the JSON response from claude-3-5-sonnet-20241022 like so (with response_format == {"type": "json_object"})

response.choices[0].message.tool_calls[0].function.arguments

Which I can use but it's extra steps only if I use claude, if I use gpt then I can just do response.choices[0].message.content

@ishaan-jaff
Copy link
Contributor

Can I see the request you're making @Seluj78 ?

response.choices[0].message.tool_calls[0].function.arguments
Which I can use but it's extra steps only if I use claude, if I use gpt then I can just do response.choices[0].message.content

@ishaan-jaff
Copy link
Contributor

Able to repro with this request

litellm.completion(model='claude-3-5-sonnet-20241022', messages=[{'role': 'system', 'content': 'Your output should be a JSON object with no additional properties.  '}, {'role': 'user', 'content': 'Respond with this in json. city=San Francisco, state=CA, weather=sunny, temp=60'}], response_format={'type': 'json_object'})

@Seluj78
Copy link
Author

Seluj78 commented Nov 14, 2024

The exact problem was that response.choices[0].message.content is None because anthropic doesn't support json output inside your package

@ishaan-jaff
Copy link
Contributor

fixed here: #6748

@Seluj78
Copy link
Author

Seluj78 commented Nov 15, 2024

Amazing thanks ! Can you let me know once it's released in pypi ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants