mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-13 08:27:03 +00:00
docs: Error when importing packages from pydantic [docs] (#16564)
URL : https://python.langchain.com/docs/use_cases/extraction Desc: <b> While the following statement executes successfully, it throws an error which is described below when we use the imported packages</b> ```py from pydantic import BaseModel, Field, validator ``` Code: ```python from langchain.output_parsers import PydanticOutputParser from langchain.prompts import ( PromptTemplate, ) from langchain_openai import OpenAI from pydantic import BaseModel, Field, validator # Define your desired data structure. class Joke(BaseModel): setup: str = Field(description="question to set up a joke") punchline: str = Field(description="answer to resolve the joke") # You can add custom validation logic easily with Pydantic. @validator("setup") def question_ends_with_question_mark(cls, field): if field[-1] != "?": raise ValueError("Badly formed question!") return field ``` Error: ```md PydanticUserError: The `field` and `config` parameters are not available in Pydantic V2, please use the `info` parameter instead. For further information visit https://errors.pydantic.dev/2.5/u/validator-field-config-info ``` Solution: Instead of doing: ```py from pydantic import BaseModel, Field, validator ``` We should do: ```py from langchain_core.pydantic_v1 import BaseModel, Field, validator ``` Thanks. --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
parent
481493dbce
commit
3c387bc12d
@ -430,7 +430,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 10,
|
"execution_count": null,
|
||||||
"id": "64650362",
|
"id": "64650362",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@ -452,8 +452,8 @@
|
|||||||
"from langchain.prompts import (\n",
|
"from langchain.prompts import (\n",
|
||||||
" PromptTemplate,\n",
|
" PromptTemplate,\n",
|
||||||
")\n",
|
")\n",
|
||||||
|
"from langchain_core.pydantic_v1 import BaseModel, Field, validator\n",
|
||||||
"from langchain_openai import OpenAI\n",
|
"from langchain_openai import OpenAI\n",
|
||||||
"from pydantic import BaseModel, Field, validator\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"class Person(BaseModel):\n",
|
"class Person(BaseModel):\n",
|
||||||
@ -531,8 +531,8 @@
|
|||||||
"from langchain.prompts import (\n",
|
"from langchain.prompts import (\n",
|
||||||
" PromptTemplate,\n",
|
" PromptTemplate,\n",
|
||||||
")\n",
|
")\n",
|
||||||
|
"from langchain_core.pydantic_v1 import BaseModel, Field, validator\n",
|
||||||
"from langchain_openai import OpenAI\n",
|
"from langchain_openai import OpenAI\n",
|
||||||
"from pydantic import BaseModel, Field, validator\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Define your desired data structure.\n",
|
"# Define your desired data structure.\n",
|
||||||
|
Loading…
Reference in New Issue
Block a user