fix: preserve structured_content when ResponseLimitingMiddleware truncates#3740
fix: preserve structured_content when ResponseLimitingMiddleware truncates#3740voidborne-d wants to merge 3 commits intoPrefectHQ:mainfrom
Conversation
…cates When a tool declares an outputSchema (via return type annotation or explicit output_schema), its response includes structured_content. ResponseLimitingMiddleware dropped structured_content during truncation, producing a ToolResult with only text content. This caused downstream MCP SDK output validation to fail: 'outputSchema defined but no structured output returned' The fix preserves the original structured_content through truncation. The serialized size of structured_content is subtracted from the text budget so the combined response stays within max_size. Closes PrefectHQ#3717
|
Thanks for the report. This issue goes beyond what our contributor guidelines ask for — we just need a short problem description and an MRE. Please see our contributing guidelines and condense this issue. We'll triage it once it's trimmed down. |
Test Failure AnalysisSummary: The static analysis ( type checker) fails because a new test accesses Root Cause: In assert "[Response truncated" in result.content[0].text
Suggested Solution: Narrow the type before accessing # Before:
assert "[Response truncated" in result.content[0].text
# After:
assert isinstance(result.content[0], TextContent)
assert "[Response truncated" in result.content[0].textThis requires importing Detailed AnalysisFailing check: Log excerpt: The same Related Files
|
Narrow content[0] to TextContent before accessing .text in test_structured_content_preserved_on_truncation, fixing ty unresolved-attribute error.
|
Thanks for the PR. The diagnosis is right — truncation breaks We're going to fix this by stripping the output schema when truncation kicks in, so the SDK doesn't expect structured content that no longer applies. Closing in favor of that approach. |
Fixes #3717.
ResponseLimitingMiddlewaredropsstructured_contentwhen truncating, causingoutputSchema defined but no structured output returnedfor tools with return type annotations.Fix: Pass
structured_contentthrough_truncate_to_result()instead of discarding it. Subtract its serialized size from the text budget so combined response respectsmax_size.MRE: