-
Notifications
You must be signed in to change notification settings - Fork 14
[BUG] Fix json_schema method in the with_structured_output function. #54
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] Fix json_schema method in the with_structured_output function. #54
Conversation
Fix json_schema method in the with_structured_output function.
| method: Literal[ | ||
| "function_calling", "json_schema", "json_mode" | ||
| ] = "function_calling", | ||
| ] = "json_schema", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you double check if the langchain openai is still using function_calling as default? Changing default might introduce unexpected behavior for customer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
langchain openai is still using function_calling as default. See reference:
https://github.com/langchain-ai/langchain/blob/master/libs/partners/openai/langchain_openai/chat_models/base.py -
The note in our repo said:
If "json_schema" then it allows the user to pass a json schema (or pydantic) to the model for structured output. This is the default method.
That is why I change the default method to json_schema. I thought using function_calling as default was a typo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's probably a mistake in the docstring. Let's not update the default and move that "This is the default method." to the correct place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course. I have changed the default back to function calling. Also commented in README that please use json_schema if the default does not work.
Remove import and define an alias for the class in the init
Changed the default method for structured output in ChatOCIGenAI from 'json_schema' to 'function_calling'. Updated documentation to clarify the default and suggest alternatives if it fails.
…ith_structured_output
…th-Gemini-2.5-Models
Clarify with_structured_output methods in README
Problem
Issue link: #40
1.
with_structured_output()usemethod="function_calling"as default method. When calling Gemini 2.5 models, no function calling is returned sowith_structured_output()does not work with Gemini 2.5 models.2. If using the
json_schemamethod inwith_structured_output(),with_structured_output()was failing with a 400 error ("Please pass in correct format of request"). The root cause is that the code was passing a plain Python dict for response_format instead of proper OCI SDK objects that the GenericChatRequest API expects.Solution
json_schemamethod when the default method does not work.json_schemamethod to use proper OCI SDK objects:Testing
Now Gemini-2.5 model returns properly formatted object instead of None when using

json_schemamethod inwith_structured_output()function.