Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PydanticUserError: If you use `@root_validator` with pre=False (the default) you MUST specify `skip_on_failure=True`

I want to execute this code in google colab but I get following error:

from llama_index.prompts.prompts import SimpleInputPrompt

# Create a system prompt 
system_prompt = """[INST] <>
more string here.<>
"""

query_wrapper_prompt = SimpleInputPrompt("{query_str} [/INST]")

Error:

/usr/local/lib/python3.10/dist-packages/pydantic/_internal/_config.py:269: UserWarning: Valid config keys have changed in V2:
* 'allow_population_by_field_name' has been renamed to 'populate_by_name'
  warnings.warn(message, UserWarning)
---------------------------------------------------------------------------
PydanticUserError                         Traceback (most recent call last)
<ipython-input-36-c45796b371fe> in <cell line: 3>()
      1 # Import the prompt wrapper...
      2 # but for llama index
----> 3 from llama_index.prompts.prompts import SimpleInputPrompt
      4 # Create a system prompt
      5 system_prompt = """[INST] <>

6 frames
/usr/local/lib/python3.10/dist-packages/pydantic/deprecated/class_validators.py in root_validator(pre, skip_on_failure, allow_reuse, *__args)
    226     mode: Literal['before', 'after'] = 'before' if pre is True else 'after'
    227     if pre is False and skip_on_failure is not True:
--> 228         raise PydanticUserError(
    229             'If you use `@root_validator` with pre=False (the default) you MUST specify `skip_on_failure=True`.'
    230             ' Note that `@root_validator` is deprecated and should be replaced with `@model_validator`.',

PydanticUserError: If you use `@root_validator` with pre=False (the default) you MUST specify `skip_on_failure=True`. Note that `@root_validator` is deprecated and should be replaced with `@model_validator`.

For further information visit https://errors.pydantic.dev/2.1.1/u/root-validator-pre-skip

If I follow the link, there is no solution for my case. How can I solve that problem?

like image 849
Christian01 Avatar asked Sep 12 '25 16:09

Christian01


2 Answers

In my env, I have

pip list | grep pydantic
pydantic                     2.2.1

I fix the problem, by downgrading pydantic version

pip install pydantic==1.10.9
like image 142
j3ffyang Avatar answered Sep 15 '25 06:09

j3ffyang


Instead of downgrading pydantic, consider upgrading langchain or llama-index. For example, the error in the title doesn't occur with pydantic==2.8.2 and llama_index.core==0.10.67. Similar errors involving langchain also doesn't occur for newer versions of langchain, e.g. langchain>=0.3.0 and langchain-core>=0.3.0.1

So pip install langchain langchain-core -U should really solve the issue.


1 Some background:

  • For langchain>=0.3.0 and langchain-core>=0.3.0, langchain internally uses pydantic v2, so importing from pydantic should pose no issue.
  • For langchain>=0.0.267,<0.3.0, it internally used pydantic.v1 (the change in the repo), so explicitly importing from pydantic sometimes caused an issue due to mixing pydantic v1 and v2. To avoid this issue, if you're explicitly importing from pydantic (perhaps to use v2 functionality such as field_validator), then you shouldn't delegate other definitions related to pydantic to langchain; define all of those yourself. An easier solution for these langchain versions was to import from langchain_core.pydantic_v1 and use the objects from therein.
  • For langchain<0.0267, the error in the title commonly occurred because langchain was internally importing from pydantic when it actually wanted to use pydantic v1 (and that name became pydantic v2 which had some breaking changes).
like image 23
cottontail Avatar answered Sep 15 '25 08:09

cottontail