Skip to content

[BUG][Graph] structured_output_model prevents correct output propagation from dependencies #1118

@courtem

Description

@courtem

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.14.0

Python Version

3.13

Operating System

macOS 15.6

Installation Method

pip

Steps to Reproduce

Dependencies

python3 -m venv .venv
source .venv/bin/activate
pip install "pydantic>=2.12.0,<3.0.0" "strands-agents[otel]>=1.14.0,<2.0.0" "strands-agents-tools>=0.2.13,<1.0.0"

Code snippet

from __future__ import annotations

from typing import Annotated

from pydantic import BaseModel, Field
from strands import Agent
from strands.multiagent import GraphBuilder
from strands.telemetry import StrandsTelemetry

StrandsTelemetry().setup_console_exporter()


class Foo(BaseModel):
    foo: Annotated[str, Field(min_length=1, max_length=10)]
    bar: Annotated[str, Field(min_length=1, max_length=10)]


first_agent_system_prompt = """
The final output must strictly follow this JSON structure:

``python
class Foo(BaseModel):
    foo: Annotated[str, Field(min_length=1, max_length=10)]
    bar: Annotated[str, Field(min_length=1, max_length=10)]
``

You must output a valid JSON object conforming exactly to the schema above.
Do not include commentary, explanations, or additional text.

**Example Output:**

``json
{
    "foo": "hello",
    "bar": "world"
}
``
"""
first_agent = Agent(
    name="first_agent",
    system_prompt=first_agent_system_prompt,
    structured_output_model=Foo,
    tools=[],
)

second_agent_system_prompt = """
You must return a valid JSON object conforming exactly to the schema above.
Do not include commentary, explanations, or additional text.

**Example Output:**

``json
{
    "foo": "hello",
    "bar": "world"
}
``
"""
second_agent = Agent(
    name="second_agent",
    system_prompt=second_agent_system_prompt,
    structured_output_model=Foo,
    tools=[],
)

builder = GraphBuilder()

builder.add_node(first_agent, "first_agent")
builder.add_node(second_agent, "second_agent")

builder.add_edge("first_agent", "second_agent")

builder.set_entry_point("first_agent")

graph = builder.build()


def main():
    graph("Hello, world!")


if __name__ == "__main__":
    main()

Expected Behavior

{
    ...,
    "attributes": {
                "content": "[{\"text\": \"Original Task: Hello, world!\"}, {\"text\": \"\\nInputs from previous nodes:\"}, {\"text\": \"\\nFrom first_agent:\"}, {\"text\": \"  - Agent: {\"foo\":\"...\",\"bar\":\"...\"}\"}]"
            }
}

Actual Behavior

{
    ...,
    "attributes": {
                "content": "[{\"text\": \"Original Task: Hello, world!\"}, {\"text\": \"\\nInputs from previous nodes:\"}, {\"text\": \"\\nFrom first_agent:\"}, {\"text\": \"  - Agent: \"}]"
            }
}

Additional Context

No response

Possible Solution

No response

Related Issues

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions