langchain - 💡(How to fix) Fix # Bug Report: langchain-docling Pydantic v2 Compatibility Issue [4 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#35443Fetched 2026-04-08 00:26:07
View on GitHub
Comments
4
Participants
3
Timeline
15
Reactions
0
Timeline (top)
commented ×4mentioned ×4subscribed ×4labeled ×2

langchain-docling fails to import with a TypeError: StringConstraints() takes no arguments when using current versions of docling-core and Pydantic v2.

Error Message

File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\types_init_.py", line 3, in <module> from docling_core.types.doc.document import DoclingDocument File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\types\doc_init_.py", line 4, in <module> from .document import ( File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\types\doc\document.py", line 49, in <module> from docling_core.search.package import VERSION_PATTERN File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\search\package.py", line 17, in <module> class Package(BaseModel, extra="forbid"): File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\search\package.py", line 24, in Package version: Annotated[str, StringConstraints(strict=True, pattern=VERSION_PATTERN)] = importlib.metadata.version( TypeError: StringConstraints() takes no arguments

Root Cause

In docling_core/search/package.py line 24, the code calls:

StringConstraints(strict=True, pattern=VERSION_PATTERN)

However, in Pydantic v2.12.5, StringConstraints() does not accept positional/keyword arguments in this way. The correct syntax for Pydantic v2 is:

StringConstraints(min_length=1, pattern=VERSION_PATTERN)
# or use Field with constraints

Fix Action

Fix / Workaround

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • 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).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Workaround (if available)

  • Downgrade to older versions: pip install docling-core==2.48.0 docling==2.18.0
  • Or use an alternative document loader

Other Dependencies

async-timeout<5.0.0,>=4.0.0;: Installed. No version info available. claude-agent-sdk>=0.1.0;: Installed. No version info available. docling~=2.18: Installed. No version info available. httpx<1,>=0.23.0: Installed. No version info available. jsonpatch<2.0.0,>=1.33.0: Installed. No version info available. langchain-anthropic;: Installed. No version info available. langchain-aws;: Installed. No version info available. langchain-azure-ai;: Installed. No version info available. langchain-cohere;: Installed. No version info available. langchain-community;: Installed. No version info available. langchain-core<1.0.0,>=0.3.72: Installed. No version info available. langchain-core<2.0.0,>=0.3.75: Installed. No version info available. langchain-core~=0.3.19: Installed. No version info available. langchain-deepseek;: Installed. No version info available. langchain-fireworks;: Installed. No version info available. langchain-google-genai;: Installed. No version info available. langchain-google-vertexai;: Installed. No version info available. langchain-groq;: Installed. No version info available. langchain-huggingface;: Installed. No version info available. langchain-mistralai;: Installed. No version info available. langchain-ollama;: Installed. No version info available. langchain-openai;: Installed. No version info available. langchain-perplexity;: Installed. No version info available. langchain-text-splitters<1.0.0,>=0.3.9: Installed. No version info available. langchain-together;: Installed. No version info available. langchain-xai;: Installed. No version info available. langsmith-pyo3>=0.1.0rc2;: Installed. No version info available. langsmith<1.0.0,>=0.3.45: Installed. No version info available. langsmith>=0.1.17: Installed. No version info available. openai-agents>=0.0.3;: Installed. No version info available. opentelemetry-api>=1.30.0;: Installed. No version info available. opentelemetry-exporter-otlp-proto-http>=1.30.0;: Installed. No version info available. opentelemetry-sdk>=1.30.0;: Installed. No version info available. orjson>=3.9.14;: Installed. No version info available. packaging<26.0.0,>=23.2.0: Installed. No version info available. packaging>=23.2: Installed. No version info available. pydantic<3,>=1: Installed. No version info available. pydantic<3.0.0,>=2.7.4: Installed. No version info available. pytest>=7.0.0;: Installed. No version info available. PyYAML<7.0.0,>=5.3.0: Installed. No version info available. PyYAML>=5.3: Installed. No version info available. requests-toolbelt>=1.0.0: Installed. No version info available. requests<3,>=2: Installed. No version info available. requests>=2.0.0: Installed. No version info available. rich>=13.9.4;: Installed. No version info available. SQLAlchemy<3,>=1.4: Installed. No version info available. tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. typing-extensions<5.0.0,>=4.7.0: Installed. No version info available. uuid-utils<1.0,>=0.12.0: Installed. No version info available. vcrpy>=7.0.0;: Installed. No version info available. zstandard>=0.23.0: Installed. No version info available.

Code Example

from langchain_docling import DoclingLoader

def main():
    FILE_PATH = ["https://arxiv.org/pdf/2408.09869"]  # Docling Technical Report
    
    loader = DoclingLoader(file_path=FILE_PATH)
    docs = loader.load()

    print(f"Loaded {len(docs)} documents")
    print(docs[0].page_content[:500])  # Print first 500 characters

if __name__ == "__main__":
    main()

---

File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\types\__init__.py", line 3, in <module>
    from docling_core.types.doc.document import DoclingDocument
  File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\types\doc\__init__.py", line 4, in <module>
    from .document import (
  File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\types\doc\document.py", line 49, in <module>
    from docling_core.search.package import VERSION_PATTERN
  File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\search\package.py", line 17, in <module>
    class Package(BaseModel, extra="forbid"):
  File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\search\package.py", line 24, in Package
    version: Annotated[str, StringConstraints(strict=True, pattern=VERSION_PATTERN)] = importlib.metadata.version(
TypeError: StringConstraints() takes no arguments

---

Traceback (most recent call last):
  File "D:\arvix_benchmark\load.py", line 1, in <module>
    from langchain_docling import DoclingLoader
  File "D:\arvix_benchmark\venv\lib\site-packages\langchain_docling\__init__.py", line 7, in <module>
    from langchain_docling.loader import DoclingLoader
  File "D:\arvix_benchmark\venv\lib\site-packages\langchain_docling\loader.py", line 12, in <module>
    from docling.chunking import BaseChunk, BaseChunker, HybridChunker
  ...
  File "D:\arvix_benchmark\venv\lib\site-packages\docling_core\search\package.py", line 17, in <module>
    class Package(BaseModel, extra="forbid"):
  File "D:\arvix_benchmark\venv\lib\site-packages\docling_core\search\package.py", line 24, in Package
    version: Annotated[str, StringConstraints(strict=True, pattern=VERSION_PATTERN)] = ...
TypeError: StringConstraints() takes no arguments

---

StringConstraints(strict=True, pattern=VERSION_PATTERN)

---

StringConstraints(min_length=1, pattern=VERSION_PATTERN)
# or use Field with constraints
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • 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).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

No response

Reproduction Steps / Example Code (Python)

from langchain_docling import DoclingLoader

def main():
    FILE_PATH = ["https://arxiv.org/pdf/2408.09869"]  # Docling Technical Report
    
    loader = DoclingLoader(file_path=FILE_PATH)
    docs = loader.load()

    print(f"Loaded {len(docs)} documents")
    print(docs[0].page_content[:500])  # Print first 500 characters

if __name__ == "__main__":
    main()

Error Message and Stack Trace (if applicable)

File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\types\__init__.py", line 3, in <module>
    from docling_core.types.doc.document import DoclingDocument
  File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\types\doc\__init__.py", line 4, in <module>
    from .document import (
  File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\types\doc\document.py", line 49, in <module>
    from docling_core.search.package import VERSION_PATTERN
  File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\search\package.py", line 17, in <module>
    class Package(BaseModel, extra="forbid"):
  File "d:\arvix_benchmark\venv\lib\site-packages\docling_core\search\package.py", line 24, in Package
    version: Annotated[str, StringConstraints(strict=True, pattern=VERSION_PATTERN)] = importlib.metadata.version(
TypeError: StringConstraints() takes no arguments

Description

Bug Report: langchain-docling Pydantic v2 Compatibility Issue

Summary

langchain-docling fails to import with a TypeError: StringConstraints() takes no arguments when using current versions of docling-core and Pydantic v2.

Environment

  • Python: 3.9.7
  • langchain-docling: 1.1.0
  • docling: 2.69.1
  • docling-core: 2.60.1
  • pydantic: 2.12.5
  • OS: Windows 10

Error Trace

Traceback (most recent call last):
  File "D:\arvix_benchmark\load.py", line 1, in <module>
    from langchain_docling import DoclingLoader
  File "D:\arvix_benchmark\venv\lib\site-packages\langchain_docling\__init__.py", line 7, in <module>
    from langchain_docling.loader import DoclingLoader
  File "D:\arvix_benchmark\venv\lib\site-packages\langchain_docling\loader.py", line 12, in <module>
    from docling.chunking import BaseChunk, BaseChunker, HybridChunker
  ...
  File "D:\arvix_benchmark\venv\lib\site-packages\docling_core\search\package.py", line 17, in <module>
    class Package(BaseModel, extra="forbid"):
  File "D:\arvix_benchmark\venv\lib\site-packages\docling_core\search\package.py", line 24, in Package
    version: Annotated[str, StringConstraints(strict=True, pattern=VERSION_PATTERN)] = ...
TypeError: StringConstraints() takes no arguments

Root Cause

In docling_core/search/package.py line 24, the code calls:

StringConstraints(strict=True, pattern=VERSION_PATTERN)

However, in Pydantic v2.12.5, StringConstraints() does not accept positional/keyword arguments in this way. The correct syntax for Pydantic v2 is:

StringConstraints(min_length=1, pattern=VERSION_PATTERN)
# or use Field with constraints

Steps to Reproduce

  1. Create a Python 3.9+ environment
  2. Install: pip install langchain-docling pydantic>=2.0
  3. Try to import: from langchain_docling import DoclingLoader
  4. Error occurs

Expected Behavior

langchain-docling should import successfully and be usable with Pydantic v2.x

Actual Behavior

Import fails with TypeError: StringConstraints() takes no arguments

Suggested Fix

Update docling-core to use Pydantic v2 syntax for StringConstraints, or pin pydantic to a compatible version in setup.py/pyproject.toml.

Workaround (if available)

  • Downgrade to older versions: pip install docling-core==2.48.0 docling==2.18.0
  • Or use an alternative document loader

Report this to:

System Info

System Information

OS: Windows OS Version: 10.0.22631 Python Version: 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]

Package Information

langchain_core: 0.3.83 langchain: 0.3.27 langsmith: 0.4.37 langchain_docling: 1.1.0 langchain_text_splitters: 0.3.11

Optional packages not installed

langserve

Other Dependencies

async-timeout<5.0.0,>=4.0.0;: Installed. No version info available. claude-agent-sdk>=0.1.0;: Installed. No version info available. docling~=2.18: Installed. No version info available. httpx<1,>=0.23.0: Installed. No version info available. jsonpatch<2.0.0,>=1.33.0: Installed. No version info available. langchain-anthropic;: Installed. No version info available. langchain-aws;: Installed. No version info available. langchain-azure-ai;: Installed. No version info available. langchain-cohere;: Installed. No version info available. langchain-community;: Installed. No version info available. langchain-core<1.0.0,>=0.3.72: Installed. No version info available. langchain-core<2.0.0,>=0.3.75: Installed. No version info available. langchain-core~=0.3.19: Installed. No version info available. langchain-deepseek;: Installed. No version info available. langchain-fireworks;: Installed. No version info available. langchain-google-genai;: Installed. No version info available. langchain-google-vertexai;: Installed. No version info available. langchain-groq;: Installed. No version info available. langchain-huggingface;: Installed. No version info available. langchain-mistralai;: Installed. No version info available. langchain-ollama;: Installed. No version info available. langchain-openai;: Installed. No version info available. langchain-perplexity;: Installed. No version info available. langchain-text-splitters<1.0.0,>=0.3.9: Installed. No version info available. langchain-together;: Installed. No version info available. langchain-xai;: Installed. No version info available. langsmith-pyo3>=0.1.0rc2;: Installed. No version info available. langsmith<1.0.0,>=0.3.45: Installed. No version info available. langsmith>=0.1.17: Installed. No version info available. openai-agents>=0.0.3;: Installed. No version info available. opentelemetry-api>=1.30.0;: Installed. No version info available. opentelemetry-exporter-otlp-proto-http>=1.30.0;: Installed. No version info available. opentelemetry-sdk>=1.30.0;: Installed. No version info available. orjson>=3.9.14;: Installed. No version info available. packaging<26.0.0,>=23.2.0: Installed. No version info available. packaging>=23.2: Installed. No version info available. pydantic<3,>=1: Installed. No version info available. pydantic<3.0.0,>=2.7.4: Installed. No version info available. pytest>=7.0.0;: Installed. No version info available. PyYAML<7.0.0,>=5.3.0: Installed. No version info available. PyYAML>=5.3: Installed. No version info available. requests-toolbelt>=1.0.0: Installed. No version info available. requests<3,>=2: Installed. No version info available. requests>=2.0.0: Installed. No version info available. rich>=13.9.4;: Installed. No version info available. SQLAlchemy<3,>=1.4: Installed. No version info available. tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. typing-extensions<5.0.0,>=4.7.0: Installed. No version info available. uuid-utils<1.0,>=0.12.0: Installed. No version info available. vcrpy>=7.0.0;: Installed. No version info available. zstandard>=0.23.0: Installed. No version info available.

extent analysis

Fix Plan

Update docling-core to use Pydantic v2 syntax

Step-by-Step Solution

  1. Update docling-core:

    • Run pip install docling-core==2.60.1 to install the latest version compatible with Pydantic v2.
    • Alternatively, you can update the setup.py/pyproject.toml file to pin pydantic to a compatible version.
  2. Update langchain-docling:

    • Run pip install langchain-docling==1.1.0 to install the latest version compatible with docling-core v2.60.1.
  3. Verify the fix:

    • Run the reproduction code again to ensure the error is resolved.

Verification

  • Run the reproduction code and verify that the error is resolved.
  • Check the output of the code to ensure it is as expected.

Extra Tips

  • Always check the documentation and changelogs for the libraries you are using to ensure you are using the latest compatible versions.
  • Be cautious when updating dependencies, as it may break other parts of your code.
  • Consider using a virtual environment to isolate your project's dependencies and avoid conflicts with other projects.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING