i recently switched to try
claude-sonnet-5
and now i getting intermittent issues with
class Classification(BaseModel):
transaction_id: str = Field(description="transaction id")
transaction_type: str = Field(description="classification of the transaction")
reasoning: str = Field(description="reason of the classification, including any applicable special instructions")
class Classifications(BaseModel):
classifications: list[Classification] = Field(description="list of transaction classifications")
structured_llm = self.chat.with_structured_output(Classifications)
while im expecting a Classification object from the call the llm seems to return a structure that’s can be transformed into the pydantic object due to double enveloping response.
[{"type":"tool_call","id":"toolu_011fM8mzebeLLaxUPRDccHqa","name":"Classifications","args":{"classifications":"{\"classifications\": [{\"transaction_id\": \"5491661-01-20241205\", \"transaction_type\": \"water\", \"reasoning\": \"This transaction represents a water bill invoice for the property at 34 Karoro Rd Flat Bush, including water consumption, wastewater consumption, and wastewater fixed charges. Although the amount is shown as positive, the details indicate this is a water utility invoice due to be paid (due_date 27/12/2024), consistent with a payment for water services rather than income.\"}]}"}}]
classification is double enveloped, causing
1 validation error for Classifications
classifications
Input should be a valid list [
type=list_type,
input_value='{"classifications": [{"t...rather than income."}]}',
input_type=str
]
For further information visit https://errors.pydantic.dev/2.12/v/list_typeTraceback (most recent call last):
File "/root/.cache/pypoetry/virtualenvs/in-the-black-47xJI4oC-py3.12/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2060, in _call_with_config
context.run(
File "/root/.cache/pypoetry/virtualenvs/in-the-black-47xJI4oC-py3.12/lib/python3.12/site-packages/langchain_core/runnables/config.py", line 461, in call_func_with_variable_args
return func(input, **kwargs) # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/in-the-black-47xJI4oC-py3.12/lib/python3.12/site-packages/langchain_core/output_parsers/base.py", line 208, in <lambda>
lambda inner_input: self.parse_result(
^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/in-the-black-47xJI4oC-py3.12/lib/python3.12/site-packages/langchain_core/output_parsers/openai_tools.py", line 369, in parse_result
pydantic_objects.append(
tool(
**res[
"args"
]
)
)
^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/in-the-black-47xJI4oC-py3.12/lib/python3.12/site-packages/pydantic/main.py", line 250, in __init__
validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for Classifications
classifications
Input should be a valid list [
type=list_type,
input_value='{"classifications": [{"t...rather than income."}]}',
input_type=str
]
For further information visit https://errors.pydantic.dev/2.12/v/list_type