Skip to content

[BUG] Structured outputs get stuck with Bedrock models #687

@isohrab

Description

@isohrab

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

Operating System

MacOS

Installation Method

pip

Steps to Reproduce

import logging
import boto3
from pydantic import BaseModel, Field
from strands import Agent, tool
from strands.models import BedrockModel

logging.basicConfig(
    level=logging.DEBUG,
    format="%(asctime)s [%(levelname)s] %(name)s: %(message)s"
)

logging.getLogger().setLevel(logging.DEBUG)

session = boto3.Session(
    region_name='us-east-1',
    profile_name='my-profile' 
)

# Create a BedrockModel
bedrock_model = BedrockModel(
    model_id="us.amazon.nova-lite-v1:0", # or any other models
    temperature=1,
    boto_session=session
)

@tool
def weather(location: str) -> str:
    """Get weather information for a location.

    Args:
        location: City or location name
    """
    return f"Weather for {location}: Sunny, 72°F"


class LocationInfo(BaseModel):
    city: str = Field(..., description="the name of the city")
    temperature: float = Field(..., description="the the temperature of the city")

agent = Agent(model=bedrock_model, tools=[weather])
res = agent("what is the weather in Paris?") # it works
res2 = agent.structured_output(LocationInfo, res) # <--- stuck here
print(res2)

This code works with other providers such as OpenAiModel.

Expected Behavior

Return LocationInfo

Actual Behavior

stuck until stop manually with ctrl+c

This is the log after ctrl+c

^C^CThe weather in Paris is sunny, and the temperature is 72°F.Traceback (most recent call last):
  File "/Users/bob/dev/tutorials/test/.venv/lib/python3.12/site-packages/strands/agent/agent.py", line 426, in structured_output
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/bob/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/concurrent/futures/_base.py", line 451, in result
    self._condition.wait(timeout)
  File "/Users/bob/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/threading.py", line 355, in wait
    waiter.acquire()
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/bob/dev/tutorials/test/main.py", line 53, in <module>
    res2 = agent.structured_output(LocationInfo, res)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bob/dev/tutorials/test/.venv/lib/python3.12/site-packages/strands/agent/agent.py", line 424, in structured_output
    with ThreadPoolExecutor() as executor:
         ^^^^^^^^^^^^^^^^^^^^
  File "/Users/bob/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/concurrent/futures/_base.py", line 647, in __exit__
    self.shutdown(wait=True)
  File "/Users/bob/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/concurrent/futures/thread.py", line 239, in shutdown
    t.join()
  File "/Users/bob/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/threading.py", line 1149, in join
    self._wait_for_tstate_lock()
  File "/Users/bob/.local/share/uv/python/cpython-3.12.11-macos-aarch64-none/lib/python3.12/threading.py", line 1169, in _wait_for_tstate_lock
    if lock.acquire(block, timeout):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt

Additional Context

No response

Possible Solution

No response

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions