mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-18 08:03:36 +00:00
core[minor]: Prevent PydanticOutputParser from encoding schema as ASCII (#25386)
This allows users to provide parameter descriptions in the pydantic models in other languages. Continuing this PR: https://github.com/langchain-ai/langchain/pull/24809
This commit is contained in:
@@ -100,3 +100,24 @@ def test_pydantic_output_parser_type_inference() -> None:
|
||||
"title": "SampleModel",
|
||||
"type": "object",
|
||||
}
|
||||
|
||||
|
||||
def test_format_instructions_preserves_language() -> None:
|
||||
"""Test format instructions does not attempt to encode into ascii."""
|
||||
from langchain_core.pydantic_v1 import BaseModel, Field
|
||||
|
||||
description = (
|
||||
"你好, こんにちは, नमस्ते, Bonjour, Hola, "
|
||||
"Olá, 안녕하세요, Jambo, Merhaba, Γειά σου"
|
||||
)
|
||||
|
||||
class Foo(BaseModel):
|
||||
hello: str = Field(
|
||||
description=(
|
||||
"你好, こんにちは, नमस्ते, Bonjour, Hola, "
|
||||
"Olá, 안녕하세요, Jambo, Merhaba, Γειά σου"
|
||||
)
|
||||
)
|
||||
|
||||
parser = PydanticOutputParser(pydantic_object=Foo) # type: ignore
|
||||
assert description in parser.get_format_instructions()
|
||||
|
Reference in New Issue
Block a user