langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
92.71k stars 14.85k forks source link

SharePointLoader: Pydantic Validation Error in _O365Settings Due to Extra Fields in .env File #26850

Closed Raj725 closed 19 minutes ago

Raj725 commented 2 hours ago

Checked other resources

Example Code

from langchain_community.document_loaders import SharePointLoader

sp_loader = SharePointLoader( document_library_id="drive-id", )

docs = sp_loader.load()

Error Message and Stack Trace (if applicable)

pydantic_core._pydantic_core.ValidationError: 2 validation errors for _O365Settings openai_api_key Extra inputs are not permitted [type=extra_forbidden, input_value='sk-proj-AwsD-exKM2Mq-p4W...mSSZU1xSCpf8O022nVA3tIA', input_type=str] For further information visit https://errors.pydantic.dev/2.9/v/extra_forbidden pg_connection_string Extra inputs are not permitted [type=extra_forbidden, input_value='postgresql://postgres:xxxxxxxx/postgres', input_type=str] For further information visit https://errors.pydantic.dev/2.9/v/extra_forbidden

Description

I am encountering a pydantic_core._pydantic_core.ValidationError when trying to use the SharePointLoader, which internally loads _O365Settings from the .env file. The error indicates that extra inputs are not permitted, causing the validation to fail.

The issue appears to be due to additional fields (openai_api_key and pg_connection_string) in the .env file that are not defined in the _O365Settings class. This results in the validation failing with the extra_forbidden error type.

My .env file looks like:

# 0365 configuration
O365_CLIENT_ID=XXX-XXX-XXX
O365_CLIENT_SECRET=XXX-XXX-XXX

# OpenAI credentials
OPENAI_API_KEY=XXX-XXX-XXX

# Postgres configuration
PG_CONNECTION_STRING = "postgresql://postgres:xxxxx@localhost:5432/postgress"

System Info

System Information

OS: Darwin OS Version: Darwin Kernel Version 24.0.0: Mon Aug 12 20:52:31 PDT 2024; root:xnu-11215.1.10~2/RELEASE_ARM64_T6030 Python Version: 3.9.6 (default, Aug 9 2024, 14:24:13) [Clang 16.0.0 (clang-1600.0.26.3)]

Package Information

langchain_core: 0.3.0 langchain: 0.3.0 langchain_community: 0.3.0 langsmith: 0.1.120 langchain_experimental: 0.3.0 langchain_openai: 0.2.0 langchain_standard_tests: 0.1.1 langchain_text_splitters: 0.3.0

Optional packages not installed

langgraph langserve

Other Dependencies

aiohttp: 3.10.5 async-timeout: 4.0.3 dataclasses-json: 0.6.7 httpx: 0.27.2 jsonpatch: 1.33 numpy: 1.26.4 openai: 1.45.1 orjson: 3.10.7 packaging: 24.1 pydantic: 2.9.1 pydantic-settings: 2.5.2 pytest: 7.4.4 PyYAML: 6.0.2 requests: 2.32.3 SQLAlchemy: 2.0.34 syrupy: 4.7.1 tenacity: 8.5.0 tiktoken: 0.7.0 typing-extensions: 4.12.2

Raj725 commented 2 hours ago

I have identified the solution to the issue. However, I believe this problem is prevalent across multiple Langchain modules wherever SettingsConfigDict is utilized. I am raising a PR to address the fix for _O365Settings.