Skip to content

[BUG] Circular reference when structured_output detects 0 required fields #695

@zastrowm

Description

@zastrowm

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

1.4.0

Python Version

3.12

Operating System

MacOS

Installation Method

git clone

Steps to Reproduce

from typing import List
from pydantic import BaseModel, Field
from strands import tool, Agent

class ExampleFailure(BaseModel):
    ages: List[str] = Field(default_factory = list)
    names: List[str] = Field(default_factory = list)

agent = Agent(system_prompt="You excel at structured output")
agent.structured_output(AntiPatternOutput, "Name=Joe, age=88")

Expected Behavior

It works

Actual Behavior

Error message:

File structured_output.py:80, in _flatten_schema(schema)
     78     flattened["required"] = required_props
     79 else:
---> 80     raise ValueError("Circular reference detected and not supported")
     82 return flattened

ValueError: Circular reference detected and not supported

Additional Context

No response

Possible Solution

No response

Related Issues

No response

Metadata

Metadata

Assignees

Labels

area-structured-outputRelated to the structured output apibugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions