mirror of
https://github.com/hwchase17/langchain.git
synced 2025-11-13 08:13:44 +00:00
**Issue:**[ #309070](https://github.com/langchain-ai/langchain/issues/30970) **Cause** Arg type in python code ``` arg: Union[SubSchema1, SubSchema2] ``` is translated to `anyOf` in **json schema** ``` "anyOf" : [{sub schema 1 ...}, {sub schema 1 ...}] ``` The value of anyOf is a list sub schemas. The bug is caused since the sub schemas inside `anyOf` list is not taken care of. The location where the issue happens is `convert_to_openai_function` function -> `_recursive_set_additional_properties_false` function, that recursively adds `"additionalProperties": false` to json schema which is [required by OpenAI's strict function calling](https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#additionalproperties-false-must-always-be-set-in-objects) **Solution:** This PR fixes this issue by iterating each sub schema inside `anyOf` list. A unit test is added. **Twitter handle:** shengboma If no one reviews your PR within a few days, please @-mention one of baskaryan, eyurtsev, ccurme, vbarda, hwchase17. --------- Co-authored-by: ccurme <chester.curme@gmail.com>