mirror of
https://github.com/hwchase17/langchain.git
synced 2025-05-29 19:18:53 +00:00
Hello. First of all, thank you for maintaining such a great project. ## Description In https://github.com/langchain-ai/langchain/pull/25123, support for structured_output is added. However, `"additionalProperties": false` needs to be included at all levels when a nested object is generated. error from current code: https://gist.github.com/fufufukakaka/e9b475300e6934853d119428e390f204 ``` BadRequestError: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'JokeWithEvaluation': In context=('properties', 'self_evaluation'), 'additionalProperties' is required to be supplied and to be false", 'type': 'invalid_request_error', 'param': 'response_format', 'code': None}} ``` Reference: [Introducing Structured Outputs in the API](https://openai.com/index/introducing-structured-outputs-in-the-api/) ```json { "model": "gpt-4o-2024-08-06", "messages": [ { "role": "system", "content": "You are a helpful math tutor." }, { "role": "user", "content": "solve 8x + 31 = 2" } ], "response_format": { "type": "json_schema", "json_schema": { "name": "math_response", "strict": true, "schema": { "type": "object", "properties": { "steps": { "type": "array", "items": { "type": "object", "properties": { "explanation": { "type": "string" }, "output": { "type": "string" } }, "required": ["explanation", "output"], "additionalProperties": false } }, "final_answer": { "type": "string" } }, "required": ["steps", "final_answer"], "additionalProperties": false } } } } ``` In the current code, `"additionalProperties": false` is only added at the last level. This PR introduces the `_add_additional_properties_key` function, which recursively adds `"additionalProperties": false` to the entire JSON schema for the request. Twitter handle: `@fukkaa1225` Thank you! --------- Co-authored-by: Bagatur <baskaryan@gmail.com> |
||
---|---|---|
.. | ||
_api | ||
beta | ||
callbacks | ||
document_loaders | ||
documents | ||
embeddings | ||
example_selectors | ||
graph_vectorstores | ||
indexing | ||
language_models | ||
load | ||
messages | ||
output_parsers | ||
outputs | ||
prompts | ||
pydantic_v1 | ||
runnables | ||
tools | ||
tracers | ||
utils | ||
vectorstores | ||
__init__.py | ||
agents.py | ||
caches.py | ||
chat_history.py | ||
chat_loaders.py | ||
chat_sessions.py | ||
env.py | ||
exceptions.py | ||
globals.py | ||
memory.py | ||
prompt_values.py | ||
py.typed | ||
rate_limiters.py | ||
retrievers.py | ||
stores.py | ||
structured_query.py | ||
sys_info.py |