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

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

Closed
5 tasks done
Raj725 opened this issue Sep 25, 2024 · 1 comment
Closed
5 tasks done
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@Raj725
Copy link
Contributor

Raj725 commented Sep 25, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

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

@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Sep 25, 2024
@Raj725
Copy link
Contributor Author

Raj725 commented Sep 25, 2024

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.

eyurtsev pushed a commit that referenced this issue Sep 25, 2024
…tings due to extra fields in .env file (#26851)

**Description:** Fix validation error in _O365Settings by ignoring extra
fields in .env file
**Issue:** #26850
**Dependencies:** NA
@Raj725 Raj725 closed this as completed Sep 25, 2024
eyurtsev pushed a commit that referenced this issue Sep 25, 2024
…ultiple Langchain modules (#26852)

- **Description:** This pull request addresses the validation error in
`SettingsConfigDict` due to extra fields in the `.env` file. The issue
is prevalent across multiple Langchain modules. This fix ensures that
extra fields in the `.env` file are ignored, preventing validation
errors.
  **Changes include:**
    - Applied fixes to modules using `SettingsConfigDict`.

- **Issue:** NA, similar
#26850
- **Dependencies:** NA
Sheepsta300 pushed a commit to Sheepsta300/langchain that referenced this issue Oct 1, 2024
…tings due to extra fields in .env file (langchain-ai#26851)

**Description:** Fix validation error in _O365Settings by ignoring extra
fields in .env file
**Issue:** langchain-ai#26850
**Dependencies:** NA
Sheepsta300 pushed a commit to Sheepsta300/langchain that referenced this issue Oct 1, 2024
…ultiple Langchain modules (langchain-ai#26852)

- **Description:** This pull request addresses the validation error in
`SettingsConfigDict` due to extra fields in the `.env` file. The issue
is prevalent across multiple Langchain modules. This fix ensures that
extra fields in the `.env` file are ignored, preventing validation
errors.
  **Changes include:**
    - Applied fixes to modules using `SettingsConfigDict`.

- **Issue:** NA, similar
langchain-ai#26850
- **Dependencies:** NA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant