[BUG] LiteLLMModel.structured_output fails with JSONDecodeError on Claude Fable 5.x via Bedrock (LiteLLM sends an unforced tool, model replies in text)
Human Overview
AI-drafted by strandly-the-agent from the Claude Fable 5.2 e2e run (#5988, epic #5986). The template reserves this section for a human's own words, so it is left for a maintainer to fill in.
Checks
- [x] I have updated to the lastest minor and patch version of Strands
- [x] I have checked the documentation and this is not expected behavior
- [x] I have searched ./issues and there are no duplicates of my issue
SDK Language
Python
Strands Version
main @ 0b68b8a (litellm 1.106.7)
Language Runtime Version
Python 3.13.16
Operating System
Linux (Amazon Linux 2023, aarch64)
Installation Method
git clone
Steps to Reproduce
from pydantic import BaseModel
from strands import Agent
from strands.models.litellm import LiteLLMModel
class Weather(BaseModel):
time: str
weather: str
agent = Agent(LiteLLMModel(model_id="bedrock/global.anthropic.claude-fable-5-2"))
agent.structured_output(Weather, "How are you?")
This is tests_integ/models/test_conformance.py::test_structured_output_is_forced[litellm] with the LiteLLM provider's id switched to Fable 5.2. It fails 3/3. The same test passes with bedrock/global.anthropic.claude-sonnet-4-6.
Expected Behavior
structured_output returns a Weather instance (the test asserts output is forced even for an uninformative prompt), as it does on Claude Sonnet 4.6 and through BedrockModel on Fable 5.2 (test_structured_output_is_forced[bedrock] passes).
Actual Behavior
src/strands/models/litellm.py:409: tool_call_data = json.loads(choice.message.content)
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
→ ValueError: Failed to parse or load content into model: Expecting value: line 1 column 1 (char 0)
LiteLLMModel.structured_output takes the supports_response_schema() path (True for this id) and json.loads the message content. For Claude Sonnet 4.6 LiteLLM sends Converse outputConfig.textFormat (native JSON schema). For global.anthropic.claude-fable-5-2 it sends the schema as an unforced toolConfig tool instead (no toolChoice), and the model answers in plain text: "I'm doing well, thanks for asking! ...". bedrock/global.anthropic.claude-fable-5-1 behaves the same, so this hits every Claude 5.x model LiteLLM doesn't map to native output, not only 5.2.
Possible Solution
The root cause is probably LiteLLM's model map, which doesn't know these ids take outputConfig. On the SDK side, _structured_output_using_response_schema could fall back to _structured_output_using_tool (or raise StructuredOutputException) when the content isn't JSON and there's no tool call, instead of a bare ValueError. Note that _structured_output_using_tool forces tool_choice: any, which Claude 5.x rejects (#5156), so that fallback needs checking live too.
Additional Context
Repro script and request evidence
Direct LiteLLM call, outside Strands (litellm.completion(model=..., response_format=Weather, messages=[{"role":"user","content":"How are you?"}])):
bedrock/global.anthropic.claude-sonnet-4-6 content='{"time":"now","weather":"unknown - no location or weather data available"}'
bedrock/global.anthropic.claude-fable-5-2 content="I'm doing well, thanks for asking! How are you? ..."
bedrock/global.anthropic.claude-fable-5-1 content="I'm doing well, thank you for asking! ..."
With litellm._turn_on_debug(), the Sonnet 4.6 request body has "outputConfig": {"textFormat": {"type": "json_schema", ...}}. The Fable 5.2 request body has "toolConfig": {"tools": [...]} and no toolChoice.
Related Issues
#5986, #5988, #5156
I'd like to take this one. In LiteLLMModel.structured_output, the content from the supports_response_schema() path goes straight to json.loads, so a plain-text reply from Fable 5.x surfaces as a bare JSONDecodeError. My plan is to catch the non-JSON case when there is no tool call and raise StructuredOutputException with the model id and a short excerpt of the reply. A fallback to _structured_output_using_tool would run into the tool_choice: any problem from #5156, so I'd keep this change to the clear error unless you prefer otherwise. I'll add a unit test with a mocked LiteLLM response that returns conversational text and asserts the typed exception, plus a test that valid JSON still parses. Could a maintainer confirm and assign this to me?
Quick follow-up: I have this fix ready with unit tests (a mocked LiteLLM reply with conversational text raises StructuredOutputException with the model id and an excerpt; valid JSON still parses). Happy to open the PR as soon as a maintainer confirms the approach.