Generic tool results: render structured content items (#227)#235
Conversation
A tool result without a specialized output parser (e.g. ToolSearch) can carry a `content` list of typed items other than text/image — notably `tool_reference` blocks. The generic fallback formatter only extracted text and images, so such results rendered nothing on the result side. Now the leftover typed items are rendered with the same JSON/Markdown hybrid table used for JSON results (HTML), and as a JSON block in the Markdown renderer, alongside any text. The `content` array is the source, as it carries the structured items directly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A result that is both is_error and carries typed content items (e.g. tool_reference) renders the structured table, not error text — the is_error->read-as-text guard only covers the JSON-string path, and typed items are not error message text. This is a deliberate, reviewed choice; pin it (HTML + Markdown) so a future refactor can't reorder the guard ahead of the structured path and silently swallow it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughHTML and Markdown tool result renderers are updated to collect non- ChangesStructured Tool Result Rendering
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
Problem
A tool result for a tool without a specialized output renderer (e.g.
ToolSearch) can carry acontentlist of typed items other thantext/image— notablytool_referenceblocks. The generic fallback formatter only extracted text and images, so such results rendered nothing on the result side (the tool_use showed, but the result was blank). Fixes #227.Fix
html/tool_formatters.py,format_tool_result_content_raw): the list-content loop now collects leftover typed items intostructured_items, rendered by a new_structured_items_htmlhelper through the existing JSON/Markdown hybrid table — the same machinery used for JSON results. This inherits the depth and per-container breadth caps for free (a 250-item list falls back to a<pre>JSON dump rather than generating a 250-row table). Wired into all tails: the images branch appends it; the no-images branch returns it (alone, or after text). String, text-only, image-only, and error-string paths are unchanged.markdown/renderer.py,format_ToolResultContent): list content now renders text items as text and remaining typed items as a JSON block, instead of dumping the whole list verbatim. TheTodoWritespecial-case and the string path are unchanged.The
contentarray is the source (it carries the structured items directly), rather thantoolUseResult.is_error+ structured items — deliberate choiceWhen a result is both
is_errorand carries typed content items, it renders the structured table rather than plain error text. This is intentional and verified safe: theis_error→ read-as-text guard only applies to the JSON-string path, and genuinetool_reference(and other typed) items are not error message text. XSS posture is preserved on this path (structured items route through the sameescape=Truehybrid-table leaves; the breadth-cap fallback HTML-escapes too). Pinned by tests so a future refactor can't reorder the guard ahead of the structured path.Tests
New
test/test_generic_tool_result.py(13 cases): HTML + Markdown coverage, including the original bug (tool_reference-only → non-empty table), mixed text+structured, theis_error+structured pin, XSS escaping, breadth-cap fallback, and regressions on string / text-only / image-only / TodoWrite paths. Verified end-to-end on a real fixture (a ToolSearch result now emits structured tables where it previously rendered nothing). Fulljust cigreen; no snapshot churn.🤖 Generated with Claude Code
Summary by CodeRabbit