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

documents have error (create_structured_output_chain) #11524

Closed
Dhaizei opened this issue Oct 8, 2023 · 4 comments
Closed

documents have error (create_structured_output_chain) #11524

Dhaizei opened this issue Oct 8, 2023 · 4 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder Ɑ: models Related to LLMs or chat model modules

Comments

@Dhaizei
Copy link

Dhaizei commented Oct 8, 2023

Issue with current documentation:

https://python.langchain.com/docs/modules/chains/how_to/openai_functions

from typing import Sequence

class Person(BaseModel):
"""Identifying information about a person."""

name: str = Field(..., description="The person's name")
age: int = Field(..., description="The person's age")
fav_food: Optional[str] = Field(None, description="The person's favorite food")

prompt = ChatPromptTemplate.from_messages(
[
("system", "You are a world class algorithm for extracting information in structured formats."),
("human", "Use the given format to extract information from the following input: {input}"),
("human", "Tip: Make sure to answer in the correct format"),
]
)

class People(BaseModel):
"""Identifying information about all people in a text."""

people: Sequence[Person] = Field(..., description="The people in the text")

chain = create_structured_output_chain(People, llm, prompt, verbose=True)
chain.run(
"Sally is 13, Joey just turned 12 and loves spinach. Caroline is 10 years older than Sally."
)

no work,having some error:

ValidationError: 1 validation error for _OutputFormatter
output
value is not a valid dict (type=type_error.dict)

Idea or request for content:

No response

@dosubot dosubot bot added Ɑ: models Related to LLMs or chat model modules 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder labels Oct 8, 2023
@dosubot
Copy link

dosubot bot commented Oct 8, 2023

🤖

Hello,

Thank you for reaching out with your issue. The create_structured_output_chain function is designed to create a chain that can process structured outputs from a language model. It takes in a schema (either a dictionary or a Pydantic BaseModel), a language model, and a prompt template, and returns an instance of LLMChain.

From the error message you provided, it seems like the output from the language model is not a valid dictionary. This could be due to the language model not returning the expected structured output, or the output parser not correctly parsing the output.

Here's a few things you could try:

  1. Check the output from the language model: You can do this by setting verbose=True when calling chain.run(). This will print out the raw output from the language model. Make sure this output matches the structure defined in your People and Person models.

  2. Check your Pydantic models: Make sure the People and Person models are correctly defined and can be instantiated with the expected output from the language model.

  3. Check your prompt: Make sure the prompt you're passing to the language model is correctly formatted and is instructing the model to generate the expected structured output.

If you're still having issues after trying these steps, please provide more information about the output from the language model and the exact code you're using to create the chain and I'll be happy to help further.

Best,
Dosu

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@Dhaizei
Copy link
Author

Dhaizei commented Oct 8, 2023

just print

Entering new LLMChain chain...
Prompt after formatting:
System: You are a world class algorithm for extracting information in structured formats.
Human: Use the given format to extract information from the following input: Sally is 13, Joey just turned 12 and loves spinach. Caroline is 10 years older than Sally.
Human: Tip: Make sure to answer in the correct format

language model chatgpt 3.5 16k

@Dhaizei
Copy link
Author

Dhaizei commented Oct 8, 2023

Copy link

dosubot bot commented Feb 2, 2024

Hi, @Dhaizei

I'm helping the LangChain team manage their backlog and am marking this issue as stale. From what I understand, you raised an issue regarding an error in the documentation for the create_structured_output_chain function, which resulted in a ValidationError with the message "value is not a valid dict." Dosubot provided a detailed response with troubleshooting steps, and you shared additional details and a link to the documentation for further reference. The issue was resolved with the provided information.

Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, please let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Feb 2, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 9, 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 Feb 9, 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 🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder Ɑ: models Related to LLMs or chat model modules
Projects
None yet
Development

No branches or pull requests

1 participant