[FEATURE] Support TypeAdapter-compatible types in `structured_output`
Problem Statement
I would like the AI to return a list of results. In Pydantic, this is done with TypeAdapter:
TypeAdapter(list[Link]).validate_json(output)
I would like convert this to structured_output. Ideally directly, without needing TypeAdapter (having Strands insert it):
agent.structured_output(list[Link], " ... ")
But it would also be fine to require TypeAdapter:
agent.structured_output(TypeAdapter(list[Link]), " ... ")
Proposed Solution
No response
Use Case
I currently have a prompt that instructs the model to generate a JSON list of JSON objects. Other solutions that don't require a wrapping JSON list would be fine as well.
Alternatives Solutions
No response
Additional Context
No response
Hello @mkmeral , I'd like to contribute to this.
Hi @mkmeral, I have questions about supporting list[Link] / TypeAdapter in structured_output:
-
LLM providers need tool inputSchema to be a JSON object. Should Strands automatically wrap array/top-level non-object schemas (e.g. list[Link] -> {"response": list[Link]})?
-
For agent.structured_output(list[Link]) do you prefer: A) create a dynamic BaseModel wrapper (response: list[Link]) for schema generation and reuse BaseModel logic, or B) accept TypeAdapter internally and wrap its json_schema() if needed?
-
Should StructuredOutputTool accept Any (TypeAdapter, typing constructs, BaseModel) and normalize internally, or require callers to pass TypeAdapter/BaseModel before initialization?
-
For caching, should we use adapter.annotation as cache key or fallback to repr(annotation) as implemented?
Thanks.