Skip to content

fix(websearch-interception)!: stream native server-tool blocks to clients - #40967

Merged
mateo-berri merged 15 commits into
BerriAI:mainfrom
dkrisman:fix_fake_stream_server_tool_blocks
Oct 30, 2026
Merged

mateo-berri merged 15 commits into
BerriAI:mainfrom
dkrisman:fix_fake_stream_server_tool_blocks

Conversation

@dkrisman

@dkrisman dkrisman commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Reopens #37318, closed by the default-branch cutover, retargeted to main per the discussion

Anthropic-native clients like Claude Code searching through the proxy's web search interception got a plain text answer, so Claude Code showed zero searches. The direct search answer now opens with server_tool_use and web_search_tool_result blocks like the Anthropic API, with snippets only in its text block

The fake stream behind seven callers now keeps every tool_use field, redacted thinking data and text citations. Guardrails also scan the new blocks, and legacy post-call hook stream rewrites now reach the client

Original

Breaking change: with the native web_search tool, the direct search answer now opens with search blocks like the Anthropic API, so code reading content[0].text should find the text block by type

TLDR

Problem this solves:

  • web-search-only requests come back without native search blocks
  • Claude Code counts zero searches on those answers
  • a re-streamed Anthropic reply drops tool_use caller, redacted thinking data and text citations

How it solves it:

  • the direct search answer emits native blocks for native tool requests
  • the fake stream sends tool input as input_json_delta, citations as citations_delta, and keeps every other block field
  • non-streaming cost tracking accepts server_tool_use and web_search_tool_result blocks
  • guardrails scan the search blocks and deliver legacy hook stream rewrites
  • usage.server_tool_use.web_search_requests stays unset, since litellm would bill it at the model's search price on top of the Tavily search

User Flow

Before: an Anthropic-native client (Claude Code, the Anthropic SDK) that searches through the proxy sees no evidence a search ran

  1. Their client sends POST http://localhost:4000/v1/messages with the native tool {"type": "web_search_20250305", "name": "web_search"}, streaming or not
  2. The response carries a single text block only, no server_tool_use and no web_search_tool_result
  3. Claude Code shows Did 0 searches and SDK code finds no search blocks, though the text quotes the search

After: the same request returns the full native block set

  1. Their client sends POST http://localhost:4000/v1/messages with the native tool {"type": "web_search_20250305", "name": "web_search"}, streaming or not
  2. The response opens with server_tool_use carrying the query, then web_search_tool_result with the results, then the text block
  3. Claude Code shows Did 1 search and web_search_tool_result holds the result URLs

Relevant issues

Fixes #35333, whose re-wrapped stream main already fixed in 0485b3f. This PR fixes the same missing blocks on the direct search answer

Linear ticket

Resolves LIT-9789

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Last updated: 373df54. QA ran on f674537, and on 80da78f for the Anthropic rows. Changes since QA: guardrail scans of search blocks, snippets sent once, and typed test helpers. Proof remains valid because this config attaches no guardrail and the Anthropic rows build no direct search answer. Verification: at 373df54, 189 focused unit tests pass and the no-guardrail Live PR risk cells match, also at its merge with main

Each tree runs a live proxy with --num_workers 2 in front of bedrock/converse/us.anthropic.claude-sonnet-5-5 and a real Tavily search, with Before on the merge base a66dc50. Clients are Claude Code 2.1.296 in its real TUI, curl, and the Anthropic Python SDK 2.3.0

config.yaml
model_list:
  - model_name: claude-sonnet-5-5
    litellm_params:
      model: bedrock/converse/us.anthropic.claude-sonnet-5-5
      aws_region_name: us-east-1
search_tools:
  - search_tool_name: tavily-search
    litellm_params:
      search_provider: tavily
      api_key: os.environ/TAVILY_API_KEY
litellm_settings:
  callbacks: ["websearch_interception"]
  websearch_interception_params:
    enabled_providers: ["bedrock"]
    search_tool_name: "tavily-search"
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
Case Before After
Claude Code WebSearch Did 0 searches Did 1 search
/v1/messages non-streaming text block only 3 native blocks
/v1/messages streaming text block only 3 native blocks
Re-streamed tool_use caller dropped kept
Re-streamed text citations dropped kept
Re-streamed server_tool_use caller kept kept

Claude Code WebSearch

  1. litellm --config config.yaml --port $PORT --num_workers 2
  2. ANTHROPIC_BASE_URL=http://127.0.0.1:$PORT ANTHROPIC_AUTH_TOKEN=$LITELLM_MASTER_KEY ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-5-5 ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-sonnet-5-5 ANTHROPIC_DEFAULT_OPUS_MODEL=claude-sonnet-5-5 claude --model claude-sonnet-5-5
  3. Type Use your WebSearch tool to find the latest stable Python release, then tell me the version and cite your sources. and press Enter

Before (a66dc50), the search runs but Claude Code shows Did 0 searches in 2s

pr40967-7c37986095-before_claude_code.png

After (f674537), the same prompt shows Did 1 search in 1s

pr40967-f6745371c0-after_claude_code.png

/v1/messages non-streaming and streaming with curl

Non-streaming

curl -s http://127.0.0.1:$PORT/v1/messages -H "x-api-key: $LITELLM_MASTER_KEY" -H 'content-type: application/json' -H 'anthropic-version: 2023-06-01' \
  -d '{"model":"claude-sonnet-5-5","max_tokens":512,"stream":false,"messages":[{"role":"user","content":"What is the latest Python release? Search the web."}],"tools":[{"type":"web_search_20250305","name":"web_search","max_uses":3}]}' \
  | jq -c '[.content[] | {type, name, query: .input.query, results: (if .type == "web_search_tool_result" then (.content | length) else null end)} | with_entries(select(.value != null))]'

Before (a66dc50)

[{"type":"text"}]

After (f674537)

[{"type":"server_tool_use","name":"web_search","query":"What is the latest Python release? Search the web."},{"type":"web_search_tool_result","results":10},{"type":"text"}]

Each search result carries its title and URL, and the snippets stay in the text block only, so a client that sends the turn back as history sends them once

curl -s http://127.0.0.1:$PORT/v1/messages -H "x-api-key: $LITELLM_MASTER_KEY" -H 'content-type: application/json' -H 'anthropic-version: 2023-06-01' -d "$NON_STREAMING_BODY" \
  | jq -c '{result_keys: ([.content[] | select(.type == "web_search_tool_result") | .content[0] | keys] | first), result_chars: ([.content[] | select(.type == "web_search_tool_result")] | tostring | length), text_chars: ([.content[] | select(.type == "text") | .text] | first | length)}'
{"result_keys":["encrypted_content","page_age","title","type","url"],"result_chars":2096,"text_chars":13782}

Streaming

curl -sN http://127.0.0.1:$PORT/v1/messages -H "x-api-key: $LITELLM_MASTER_KEY" -H 'content-type: application/json' -H 'anthropic-version: 2023-06-01' \
  -d '{"model":"claude-sonnet-5-5","max_tokens":512,"stream":true,"messages":[{"role":"user","content":"What is the latest Python release? Search the web."}],"tools":[{"type":"web_search_20250305","name":"web_search","max_uses":3}]}' \
  | sed -n 's/^data: //p' | jq -c 'select(.type == "content_block_start" or (.delta.type? == "input_json_delta")) | if .type == "content_block_start" then {index, start: .content_block.type} else {index, input_json_delta: .delta.partial_json} end'

Before (a66dc50)

{"index":0,"start":"text"}

After (f674537)

{"index":0,"start":"server_tool_use"}
{"index":0,"input_json_delta":"{\"query\": \"What is the latest Python release? Search the web.\"}"}
{"index":1,"start":"web_search_tool_result"}
{"index":2,"start":"text"}
Anthropic replies re-streamed through the fake stream

A second config points claude-sonnet-5-5 at anthropic/claude-sonnet-5-5 with enabled_providers: ["anthropic"], so the interception makes one non-streaming call and re-streams Anthropic's reply. Every request below streams and carries the web_search tool, and the model answers without searching. Both proxies ran with --num_workers 2

End-user code that reads a cited answer and a tool call made from code execution, run with ANTHROPIC_BASE_URL=http://127.0.0.1:$PORT ANTHROPIC_API_KEY=$LITELLM_MASTER_KEY python sdk_case.py

import anthropic

client = anthropic.Anthropic()

with client.messages.stream(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    tools=[{"type": "web_search_20250305", "name": "web_search"}],
    messages=[{"role": "user", "content": [
        {"type": "document", "source": {"type": "text", "media_type": "text/plain", "data": "The release team shipped version 4.2 on March 3. The next release, 4.3, is planned for June 9."}, "title": "Release notes", "citations": {"enabled": True}},
        {"type": "text", "text": "When is the next release planned? Answer only from the document and cite it."},
    ]}],
) as stream:
    text = stream.get_final_message().content[0]
print("citations:", [c.cited_text for c in text.citations or []])

with client.messages.stream(
    model="claude-sonnet-5-5",
    max_tokens=2048,
    tools=[
        {"type": "web_search_20250305", "name": "web_search"},
        {"type": "code_execution_20260120", "name": "code_execution"},
        {"name": "get_weather", "description": "Get the weather for a city", "input_schema": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}, "allowed_callers": ["code_execution_20260120"]},
    ],
    messages=[{"role": "user", "content": "Write code that calls get_weather for Paris and returns the result."}],
) as stream:
    blocks = stream.get_final_message().content
print("get_weather caller:", [b.caller.type if b.caller else None for b in blocks if b.type == "tool_use"])

Before (a66dc50)

citations: []
get_weather caller: [None]

After (80da78f)

citations: ['The next release, 4.3, is planned for June 9.']
get_weather caller: ['code_execution_20260120']

The same cited answer with curl

curl -sN http://127.0.0.1:$PORT/v1/messages -H "x-api-key: $LITELLM_MASTER_KEY" -H 'content-type: application/json' -H 'anthropic-version: 2023-06-01' \
  -d '{"model":"claude-sonnet-5-5","max_tokens":1024,"stream":true,"tools":[{"type":"web_search_20250305","name":"web_search"}],"messages":[{"role":"user","content":[{"type":"document","source":{"type":"text","media_type":"text/plain","data":"The release team shipped version 4.2 on March 3. The next release, 4.3, is planned for June 9."},"title":"Release notes","citations":{"enabled":true}},{"type":"text","text":"When is the next release planned? Answer only from the document and cite it."}]}]}' \
  | sed -n 's/^data: //p' | jq -c 'select((.type == "content_block_start" and .content_block.type == "text") or (.delta.type? == "citations_delta")) | if .type == "content_block_start" then {index, start: "text", citations: .content_block.citations} else {index, citations_delta: .delta.citation.cited_text} end'

Before (a66dc50)

{"index":0,"start":"text","citations":null}

After (80da78f)

{"index":0,"start":"text","citations":[]}
{"index":0,"citations_delta":"The next release, 4.3, is planned for June 9."}

The same tool call with curl

curl -sN http://127.0.0.1:$PORT/v1/messages -H "x-api-key: $LITELLM_MASTER_KEY" -H 'content-type: application/json' -H 'anthropic-version: 2023-06-01' \
  -d '{"model":"claude-sonnet-5-5","max_tokens":2048,"stream":true,"messages":[{"role":"user","content":"Write code that calls get_weather for Paris and returns the result."}],"tools":[{"type":"web_search_20250305","name":"web_search"},{"type":"code_execution_20260120","name":"code_execution"},{"name":"get_weather","description":"Get the weather for a city","input_schema":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]},"allowed_callers":["code_execution_20260120"]}]}' \
  | sed -n 's/^data: //p' | jq -c 'select(.type == "content_block_start" and .content_block.type == "tool_use") | {index, name: .content_block.name, caller: .content_block.caller}'

Before (a66dc50)

{"index":1,"name":"get_weather","caller":null}

After (80da78f)

{"index":1,"name":"get_weather","caller":{"type":"code_execution_20260120","tool_id":"srvtoolu_01HbY1hzZmmaVS9s28D55Hm1"}}

A server_tool_use from code execution kept caller on both trees

curl -sN http://127.0.0.1:$PORT/v1/messages -H "x-api-key: $LITELLM_MASTER_KEY" -H 'content-type: application/json' -H 'anthropic-version: 2023-06-01' \
  -d '{"model":"claude-sonnet-5-5","max_tokens":2048,"stream":true,"messages":[{"role":"user","content":"Fetch https://www.python.org/downloads/ and tell me the latest stable Python release in one line, citing the page."}],"tools":[{"type":"web_search_20250305","name":"web_search"},{"type":"web_fetch_20260209","name":"web_fetch","citations":{"enabled":true}}]}' \
  | sed -n 's/^data: //p' | jq -c 'select(.type == "content_block_start" and .content_block.type == "server_tool_use") | {index, name: .content_block.name, caller: .content_block.caller}'

Before (a66dc50)

{"index":0,"name":"code_execution","caller":null}
{"index":1,"name":"web_fetch","caller":{"type":"code_execution_20260120","tool_id":"srvtoolu_01AATeDjRpV1fCspVfTVFGnB"}}

After (80da78f)

{"index":0,"name":"code_execution","caller":null}
{"index":1,"name":"web_fetch","caller":{"type":"code_execution_20260120","tool_id":"srvtoolu_01Ju2M7CPuv4QQ74z4i2aVGk"}}
Text-only guardrail on a streamed search

Bugbot found that a guardrail that rewrites only texts left the streamed server_tool_use query unmasked. This cell attaches a custom post_call guardrail that masks "python" in texts only, through a policy pipeline on the same Bedrock model and Tavily search. The config and the guardrail are in the gist

curl -sN http://127.0.0.1:$PORT/v1/messages -H "x-api-key: $LITELLM_MASTER_KEY" -H 'content-type: application/json' -H 'anthropic-version: 2023-06-01' \
  -d '{"model":"claude-textsonly","max_tokens":1024,"stream":true,"tools":[{"type":"web_search_20250305","name":"web_search","max_uses":8}],"system":[{"type":"text","text":"You are an assistant for performing a web search tool use"}],"messages":[{"role":"user","content":"Perform a web search for the query: python 3.14 release date"}]}' \
  | grep input_json_delta

Before the fix (8ea884d)

data: {"type": "content_block_delta", "index": 0, "delta": {"type": "input_json_delta", "partial_json": "{\"query\": \"python 3.14 release date\"}"}}

After (19336aa)

data: {"type": "content_block_delta", "index": 0, "delta": {"type": "input_json_delta", "partial_json": "{\"query\": \"[MASKED] 3.14 release date\"}"}}

The merge base a66dc50 answers with a text block only, and the non-streaming reply masks the query at both commits

Observations

  • The text block still follows the native blocks for every caller

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • A streamed direct search answer still fails success logging and writes no spend row, as on the merge base
  • usage still reports zero searches, so SDK code reading it sees none next to a server_tool_use block
  • The redacted thinking fix has no live proof, since Anthropic's redacted thinking test prompt returns plain thinking on every served model, so a unit test covers it

Low

  • Cost tracking accepts only the two search block types, so other server tool blocks still fail it as on the merge base
  • The search query is still the whole user message, as on the merge base

Live PR risk

Verdict at 373df54: safe to ship, also at its merge with main (a8cf0bbd41)

Breaking, backward incompatible, regression risk, dependency graph, not verified

The table is from 19336aa. At 373df54 every head cell answers 200 with one upstream request, the masking cells stay at 0, and the other counts move only with the search results. At its merge with main (a8cf0bbd41) the four legacy tool cells could not run because the Bedrock QA credentials expired, and they pass at 373df54 and at the earlier merge b14e46ee0c

Nothing that worked before breaks, and each change a client can see is the ticket's ask or a guardrail that now works. Every cell runs on both trees with 2 workers each, against Bedrock and Anthropic with a real Tavily search. The guardrails mask the word "python", and each count is how many matches reach the client. The counts per block, config and scripts are in this gist

Cell Before After
No guardrail text only 3 blocks
Legacy hook, stream text only, 0 3 blocks, 0
Legacy hook, non-stream text only, 0 3 blocks, 0
Text-only legacy hook text only, 0 3 blocks, 33
Legacy tool args, chat stream 1 0
Legacy tool args, responses stream 1 0
Unified mask, stream text only, 0 3 blocks, 0
Text-only unified mask, stream text only, 0 3 blocks, 0
Native Anthropic, unified mask 23 in search blocks 0 in search blocks

Breaking

None. Every cell answered 200 on both trees, and the 22 wire tests pass at e6715ba

Backward incompatible

  • The direct search answer opens with server_tool_use and web_search_tool_result before its text block. Approved by Shivam in the Expected section of LIT-9789, which asks for these blocks
  • A legacy hook that redacts only text blocks used to redact search titles, because they came back as text. They now come back in web_search_tool_result, which that hook skips, so 33 matches reach the client. Same approval, and a unified guardrail scans them since 923b9d4
  • A unified guardrail on /v1/messages now masks the search query, result titles and URLs, so a mask can change a result link. This is a control that now works, fixed in 923b9d4, and for a streamed query under a text-only guardrail in 19336aa and 373df54
  • A legacy hook's tool call rewrites on chat and responses streams now reach the client, where the whole stream rewrite was thrown away before. This is a control that now works, fixed in f980d76, with its search block rewrites in e6715ba

Regression risk

  • A tool permission guardrail on a stream still returns the direct answer as text only, as on the merge base
  • On native Anthropic streams, a legacy hook's masks of result blocks and citations still do not reach the client, as on the merge base
  • Text citations are not scanned on either tree

Dependency graph

Dependent Entry point Status
Direct search answer /v1/messages verified live
Fake stream, 7 callers /v1/messages stream verified live
Search block cost tracking /v1/messages tested
Unified guardrail write-back 3 routes verified live
Legacy hook adapter 3 routes verified live
Native Anthropic search /v1/messages verified live
Vendor guardrails any route not verified

The ranking put /v1/messages streaming and non-streaming first, then chat and responses streams with a legacy hook, then the SDK's anthropic_messages, then spend logging

Not verified

  • Presidio, Model Armor and Bedrock Guardrails on the new title and URL texts, since this node has no vendor credentials
  • Redacted thinking on a live model, per the Medium caveat
  • A streamed tool_use search block with a srvtoolu_ id, since no rig route sends one, so a unit test covers it

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
Bugbot summary

[!NOTE]
Medium Risk
Changes the default /v1/messages short-circuit payload shape and expands guardrail rewrite surfaces on streaming SSE; callers assuming content[0] is text or legacy hooks that only redact text may see different client-visible output.

Overview
Anthropic-native clients (Claude Code, SDK) that hit web-search short-circuit on /v1/messages now get server_tool_use + web_search_tool_result before the text block, including when pre-hooks already renamed the tool—the WEBSEARCH_EMIT_NATIVE_BLOCKS_KEY flag drives emission. Search snippets appear only in the text block (with_snippets=False on native result blocks) so history does not duplicate them.

The fake Anthropic stream used when interception forces non-streaming now replays server_tool_use (empty input + input_json_delta), whole web_search_tool_result blocks, server_tool_use/tool_use fields, and text citations_delta events so SDK accumulators match real API behavior.

Guardrails on Anthropic Messages now scan and write back search queries, result titles, and URLs on non-streaming and ended-stream paths, treat server_tool_use like tool calls for streaming rewrites, and prepend streamed web_search_tool_result blocks when translating post-call responses. The legacy hook stream adapter forwards tool-call rewrites when counts still match (replacing the old fail-closed rule on any argument change).

Response typing adds server_tool_use and web_search_tool_result to the allowed content union.

Reviewed by Cursor Bugbot for commit 373df54. Bugbot is set up for automated code reviews on this repo. Configure here.

@dkrisman
dkrisman requested a review from a team September 13, 2026 05:39
@dkrisman
dkrisman force-pushed the fix_fake_stream_server_tool_blocks branch from 784e9eb to ccc72ea Compare September 26, 2026 07:24
@codecov

codecov Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.62842% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ms/anthropic/chat/guardrail_translation/handler.py 94.32% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 42 untouched benchmarks


Comparing dkrisman:fix_fake_stream_server_tool_blocks (373df54) with main (4a5c566)

Open in CodSpeed

@dkrisman
dkrisman force-pushed the fix_fake_stream_server_tool_blocks branch 2 times, most recently from 7c17424 to 1691aa4 Compare October 16, 2026 07:08
Streaming native clients (Anthropic SDK, Claude Desktop, Claude Code)
never received the server_tool_use and web_search_tool_result blocks the
interception layer builds for them, so citation panels stayed empty and
result counts read zero. Two gaps in the same flow:

FakeAnthropicMessagesStreamIterator._create_content_block_chunks only
knew text, thinking, redacted_thinking and tool_use; any other block
type emitted a bare content_block_stop with no start and no payload,
silently dropping the block from the fake stream. server_tool_use now
streams as content_block_start plus input_json_delta and any other
server-generated block rides whole in content_block_start, matching
Anthropic's native streaming of these types.

try_short_circuit_search only recognized a native client by finding a
web_search_* tool in the tools list, but the pre-request and deployment
hooks convert that tool to the LiteLLM standard shape before the
short-circuit runs, recording the conversion in
WEBSEARCH_EMIT_NATIVE_BLOCKS_KEY. The flag now counts as native too, so
the synthetic response carries the native blocks on the converted path
instead of only when hook ordering happens to leave the tool untouched.

Fixes BerriAI#35333
…r_tool_blocks

# Conflicts:
#	tests/unit/llms/anthropic/messages/native/test_fake_stream_iterator.py
…cks when costing a /v1/messages response

The short-circuit now returns native web search blocks, and the cost path validated the served body against a content union that only allowed text, tool_use and thinking blocks, so non-streaming requests answered 500
…r_tool_blocks

# Conflicts:
#	tests/unit/integrations/websearch_interception/test_websearch_short_circuit.py
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge, with no new actionable issue found

Summary

The PR returns native search blocks to Anthropic clients and preserves tool fields, redacted thinking, and citations when rebuilding streams

  • Native web searches show their query and results to Anthropic clients.
  • Anthropic streams keep the full content of each response block.
  • Anthropic guardrails can mask native search queries and results.
  • Legacy post-call hooks can rewrite streamed tool calls.

Reviews (10) · Last reviewed commit: "fix(guardrails): keep the block id when ..." · Reviewed by Greptile

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri mateo-berri changed the title fix(websearch-interception): stream native server-tool blocks to clients fix(websearch-interception)!: stream native server-tool blocks to clients Oct 29, 2026
…ages and deliver stream rewrites past server_tool_use blocks

Output guardrails now scan the native web search blocks the short-circuit emits, ahead of the reply text so guardrails that read the last text still scan the reply. A guardrail reply of a different length falls back to the reply-only write-back. Ended-stream tool call rewrites land on server_tool_use blocks too, the ended-stream scan key covers the result strings, and legacy-hook pipeline steps pass through the result strings their response view lacks. The wire test reads the streamed server_tool_use input from its input_json_delta.
… on streams instead of discarding the stream rewrite

A legacy hook that masked a tool call's arguments on a buffered stream made the whole
rewrite undeliverable, text included, so the original stream went out. With web search
blocks in the stream that now hit any hook masking the search query. The adapter hands
same-count tool-call rewrites to the translation's write-back, as a unified guardrail's
already are, and still discards a rewrite that adds or drops a tool call.
…locks of a /v1/messages stream

The legacy hook's view of a buffered Anthropic stream is rebuilt from the assembled
ModelResponse, which keeps web_search_tool_result blocks only in provider-specific
fields, so a hook masking result titles on a stream never saw them. The hook's view now
carries those blocks, its rewrite of them goes back through the ended-stream write-back,
and the adapter no longer needs to pass texts outside the hook's view through untouched.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 373df54. Configure here.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the contribution!

@mateo-berri
mateo-berri merged commit 953750e into BerriAI:main Oct 30, 2026
90 of 91 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: websearch interception drops web_search_tool_result blocks when re-wrapping the stream

2 participants