You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
langchain/docs
ARKA1112 3c387bc12d
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>
8 months ago
..
api_reference docs: bump sphinx>=5 (#16162) 8 months ago
docs docs: Error when importing packages from pydantic [docs] (#16564) 8 months ago
scripts docs: fix llm/chat_model tables (#15716) 9 months ago
src
static docs: Update with LCEL examples to Ollama & ChatOllama Integration notebook (#16194) 8 months ago
.local_build.sh update chain docs (#15495) 9 months ago
README.md
babel.config.js
code-block-loader.js
docusaurus.config.js docs: add changelog (#15606) 9 months ago
package-lock.json
package.json
settings.ini
sidebars.js docs: add LangGraph (#15682) 9 months ago
vercel.json exa: init pkg (#16553) 8 months ago
vercel_build.sh docs: add LangGraph (#15682) 9 months ago
vercel_requirements.txt

README.md

LangChain Documentation

For more information on contributing to our documentation, see the Documentation Contributing Guide