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

[Question]: cannot import name 'BeforeValidator' from 'pydantic' - pydantic version used in llama-index? #17332

Open
1 task done
jingweibhuang opened this issue Dec 19, 2024 · 5 comments
Labels
question Further information is requested

Comments

@jingweibhuang
Copy link

Question Validation

  • I have searched both the documentation and discord for an answer.

Question

Hello,
I got the following import error when importing as follows:

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader


ImportError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

File ~/pro/mambaforge/envs/env_cuda121c/lib/python3.10/site-packages/llama_index/core/init.py:16
13 pass
15 # response
---> 16 from llama_index.core.base.response.schema import Response
18 # import global eval handler
19 from llama_index.core.callbacks.global_handlers import set_global_handler

File ~/pro/mambaforge/envs/env_cuda121c/lib/python3.10/site-packages/llama_index/core/base/response/schema.py:7
4 from dataclasses import dataclass, field
5 from typing import Any, Dict, List, Optional, Union
----> 7 from llama_index.core.async_utils import asyncio_run
8 from llama_index.core.bridge.pydantic import BaseModel
9 from llama_index.core.schema import NodeWithScore

File ~/pro/mambaforge/envs/env_cuda121c/lib/python3.10/site-packages/llama_index/core/async_utils.py:7
4 from itertools import zip_longest
5 from typing import Any, Coroutine, Iterable, List, Optional, TypeVar
----> 7 import llama_index.core.instrumentation as instrument
9 dispatcher = instrument.get_dispatcher(name)
12 def asyncio_module(show_progress: bool = False) -> Any:

File ~/pro/mambaforge/envs/env_cuda121c/lib/python3.10/site-packages/llama_index/core/instrumentation/init.py:5
2 from abc import ABC
3 from typing import Any, List
----> 5 from llama_index.core.instrumentation.dispatcher import (
6 Dispatcher,
7 Manager,
8 DISPATCHER_SPAN_DECORATED_ATTR,
9 )
10 from llama_index.core.instrumentation.event_handlers import NullEventHandler
11 from llama_index.core.instrumentation.span_handlers import NullSpanHandler

File ~/pro/mambaforge/envs/env_cuda121c/lib/python3.10/site-packages/llama_index/core/instrumentation/dispatcher.py:10
8 import uuid
9 from deprecated import deprecated
---> 10 from llama_index.core.bridge.pydantic import BaseModel, Field, ConfigDict
11 from llama_index.core.instrumentation.event_handlers import BaseEventHandler
12 from llama_index.core.instrumentation.span import active_span_id

File ~/pro/mambaforge/envs/env_cuda121c/lib/python3.10/site-packages/llama_index/core/bridge/pydantic.py:2
1 import pydantic
----> 2 from pydantic import (
3 AnyUrl,
4 BaseModel,
5 BeforeValidator,
6 ConfigDict,
7 Field,
8 FilePath,
9 GetCoreSchemaHandler,
10 GetJsonSchemaHandler,
11 PlainSerializer,
12 PrivateAttr,
13 Secret,
14 SecretStr,
15 SerializeAsAny,
16 StrictFloat,
17 StrictInt,
18 StrictStr,
19 TypeAdapter,
20 ValidationError,
21 ValidationInfo,
22 WithJsonSchema,
23 WrapSerializer,
24 create_model,
25 field_serializer,
26 field_validator,
27 model_serializer,
28 model_validator,
29 )
30 from pydantic.fields import FieldInfo
31 from pydantic.json_schema import JsonSchemaValue

ImportError: cannot import name 'BeforeValidator' from 'pydantic' (/home2/xxx/.local/lib/python3.10/site-packages/pydantic/init.cpython-310-x86_64-linux-gnu.so)

I tried both pydantic 2.10 (newest version) and older 1.10. What version of pydantic is used in Llama-index, which is using BeforeValidator?

Thank you,

@jingweibhuang jingweibhuang added the question Further information is requested label Dec 19, 2024
Copy link

dosubot bot commented Dec 19, 2024

@jingweibhuang Hello! I'm here to assist you with any bugs, questions, or contributions. Let's tackle this together!

The version of Pydantic used in Llama-index that requires the 'BeforeValidator' import is ">=2.8.0" [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@jingweibhuang
Copy link
Author

@dosu Hi Dosu, Thanks a lot for quick response! Let me try 2.8 or 2.9. I already tried 2.10.
Thanks again,

Copy link

dosubot bot commented Dec 19, 2024

You're welcome! If you encounter any more issues or need further assistance, feel free to reach out. Good luck!

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@logan-markewich
Copy link
Collaborator

logan-markewich commented Dec 19, 2024

@jingweibhuang what specific version of 2.10? I know 2.10.0 was initially very breaking. I hope there wasn't another breaking change...

@jingweibhuang
Copy link
Author

Hi Logan,
Earlier I used mamba install llama-index, which installed pydantic 2.10.3 and led to the import error.
Just now I tried pip install llama-index, which installed 2.10.4 and works now:-)
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants