Skip to content

PydanticOutputParser formats error with ensure_ascii=True #34005

@soapun

Description

@soapun

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-cli
  • 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-perplexity
  • langchain-prompty
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Example Code (Python)

from langchain_core.output_parsers import PydanticOutputParser

from pydantic import BaseModel

class Value(BaseModel):
    a: int

PydanticOutputParser(pydantic_object=Value).parse('{"a": "абв"}')

Error Message and Stack Trace (if applicable)

langchain_core.exceptions.OutputParserException: Failed to parse Value from completion {"a": "\u0430\u0431\u0432"}. Got: 1 validation error for Value

Description

I am using PydanticOutputParser followed by RetryWithErrorOutputParser. This behaviour results in context noised and overflowed by \u symbols.

System Info

System Information

OS: Windows
OS Version: 10.0.19045
Python Version: 3.12.7 (main, Oct 16 2024, 00:21:24) [MSC v.1929 64 bit (AMD64)]

Package Information

langchain_core: 1.0.5
langsmith: 0.4.31
langchain_model_profiles: 0.0.4
langchain_tests: 1.0.1
langchain_text_splitters: 1.0.0

Optional packages not installed

langserve

Other Dependencies

httpx: 0.28.1
jsonpatch: 1.33
numpy: 2.3.3
orjson: 3.11.3
packaging: 25.0
pydantic: 2.12.0
pytest: 8.4.2
pytest-asyncio: 0.26.0
pytest-benchmark: 5.1.0
pytest-codspeed: 4.0.0
pytest-recording: 0.13.4
pytest-socket: 0.7.0
pyyaml: 6.0.3
requests: 2.32.5
requests-toolbelt: 1.0.0
rich: 14.1.0
syrupy: 4.9.1
tenacity: 9.1.2
typing-extensions: 4.15.0
vcrpy: 7.0.0
zstandard: 0.25.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugRelated to a bug, vulnerability, unexpected error with an existing featurecoreRelated to the package `langchain-core`

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions