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

convert_to_openai_function will drop title field in output_schema if it's a Pydantic model. #18319

Closed
5 tasks done
elonzh opened this issue Feb 29, 2024 · 3 comments
Closed
5 tasks done
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🔌: openai Primarily related to OpenAI integrations Ɑ: Runnables Related to Runnables

Comments

@elonzh
Copy link

elonzh commented Feb 29, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

from pprint import pprint
from langchain_core.utils.function_calling import convert_to_openai_function
from pydantic import v1

class BiblioExtraction(v1.BaseModel):
    title: str
    authors: list[str]

f = convert_to_openai_function(BiblioExtraction)
pprint(f)

Error Message and Stack Trace (if applicable)

{'description': '',
 'name': 'BiblioExtraction',
 'parameters': {'properties': {'authors': {'items': {'type': 'string'},
                                           'type': 'array'}},
                'required': ['title', 'authors'],
                'type': 'object'}}

Description

I am trying to use langchain.chains.openai_functions.create_structured_output_runnable to extract citation information from the text, and then I found that I cannot extract the title field.

After investigation, I discovered that langchain introduced an undocumented behavior in version 0.1.4, which deletes the title field in schema.

System Info

❯ python -m langchain_core.sys_info

System Information
------------------
> OS:  Linux
> OS Version:  #1 SMP Thu Oct 5 21:02:42 UTC 2023
> Python Version:  3.10.13 (main, Nov 16 2023, 15:58:41) [GCC 11.4.0]

Package Information
-------------------
> langchain_core: 0.1.27
> langchain: 0.1.9
> langchain_community: 0.0.24
> langsmith: 0.1.5
> langchain_openai: 0.0.5

Packages not installed (Not Necessarily a Problem)
--------------------------------------------------
The following packages were not found:

> langgraph
> langserve

@dosubot dosubot bot added Ɑ: Runnables Related to Runnables 🔌: openai Primarily related to OpenAI integrations 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Feb 29, 2024
@elonzh elonzh changed the title create_structured_output_runnable will drop title field in output_schema if it's a Pydantic model. convert_to_openai_function will drop title field in output_schema if it's a Pydantic model. Mar 1, 2024
@keenborder786
Copy link
Contributor

The unexpected behaviour is caused by rm_titles being set to True by default. Also, if you urgently want to use the tool then why don't you change the spelling of your parameter e.g title to title_extracted since that will also fix your isse.

@keenborder786
Copy link
Contributor

keenborder786 commented Mar 3, 2024

@elonzh Actually I am closing the PR because that bring in unexpected breaking changes in other parts of code. I would recommend you to use alternative name for tile e.g tile_extracted. That will serve your purpose:

from pprint import pprint
from langchain_core.utils.function_calling import convert_to_openai_function
from pydantic import BaseModel

class BiblioExtraction(BaseModel):
    title_extracted: str
    authors: list[str]

f = convert_to_openai_function(BiblioExtraction)
pprint(f)

@Gregory-Gerard
Copy link

Same here. The pain is that it's not documented, and can be time-consuming to find the actual problem. For the moment I've renamed my title, but it would be nice to be able to modify this behavior via an argument, for example.

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Jun 27, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 4, 2024
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🔌: openai Primarily related to OpenAI integrations Ɑ: Runnables Related to Runnables
Projects
None yet
Development

No branches or pull requests

3 participants