openclaw - ✅(Solved) Fix Bug: Brave LLM Context API snippets silently discarded — parsed as objects but API returns plain strings [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#43701Fetched 2026-04-08 00:17:01
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
referenced ×2closed ×1cross-referenced ×1locked ×1

The Brave LLM Context API integration (tools.web.search.brave.mode: "llm-context") silently discards all extracted page content. The web_search tool returns results with empty snippets: [] arrays despite the Brave API returning rich pre-extracted text.

Root Cause

In src/agents/tools/web-search.ts, the runBraveLlmContextSearch function parses snippets as objects with a .text property:

snippets: (entry.snippets ?? []).map((s) => s.text ?? "").filter(Boolean)

But the Brave LLM Context API (/res/v1/llm/context) returns snippets as plain strings:

{
  "grounding": {
    "generic": [
      {
        "url": "https://example.com/article",
        "title": "Article Title",
        "snippets": [
          "# Heading\nActual extracted page content as a plain string...",
          "Another text chunk from the same page..."
        ]
      }
    ]
  }
}

Since "some string".text evaluates to undefined, every snippet falls through to "" and is removed by .filter(Boolean). The result is that all extracted content is silently thrown away.

Fix Action

Fixed

PR fix notes

PR #46386: fix(web-search): handle Brave LLM snippet objects alongside strings

Description (problem / solution / changelog)

Problem

Brave API returns LLM snippets as either plain strings or {text} objects. The existing filter discarded non-string entries silently.

Changes

  • Updated BraveLlmContextResult.snippets type to (string | { text?: string })[]
  • Changed filter to map that handles both formats

Testing

  • pnpm build passes

Related

Closes #43701

Changed files

  • src/agents/tools/web-search.ts (modified, +8/-2)

Code Example

snippets: (entry.snippets ?? []).map((s) => s.text ?? "").filter(Boolean)

---

{
  "grounding": {
    "generic": [
      {
        "url": "https://example.com/article",
        "title": "Article Title",
        "snippets": [
          "# Heading\nActual extracted page content as a plain string...",
          "Another text chunk from the same page..."
        ]
      }
    ]
  }
}

---

curl -s "https://api.search.brave.com/res/v1/llm/context?q=best+practices+for+React+hooks" \
  -H "X-Subscription-Token: $BRAVE_API_KEY" | jq ".grounding.generic[0].snippets[0] | type"
# Returns: "string"

---

snippets: (entry.snippets ?? []).map((s) => typeof s === "string" ? s : (s.text ?? "")).filter(Boolean)
RAW_BUFFERClick to expand / collapse

Summary

The Brave LLM Context API integration (tools.web.search.brave.mode: "llm-context") silently discards all extracted page content. The web_search tool returns results with empty snippets: [] arrays despite the Brave API returning rich pre-extracted text.

Root Cause

In src/agents/tools/web-search.ts, the runBraveLlmContextSearch function parses snippets as objects with a .text property:

snippets: (entry.snippets ?? []).map((s) => s.text ?? "").filter(Boolean)

But the Brave LLM Context API (/res/v1/llm/context) returns snippets as plain strings:

{
  "grounding": {
    "generic": [
      {
        "url": "https://example.com/article",
        "title": "Article Title",
        "snippets": [
          "# Heading\nActual extracted page content as a plain string...",
          "Another text chunk from the same page..."
        ]
      }
    ]
  }
}

Since "some string".text evaluates to undefined, every snippet falls through to "" and is removed by .filter(Boolean). The result is that all extracted content is silently thrown away.

Verified Against Live API

Direct curl to the Brave LLM Context endpoint confirms:

curl -s "https://api.search.brave.com/res/v1/llm/context?q=best+practices+for+React+hooks" \
  -H "X-Subscription-Token: $BRAVE_API_KEY" | jq ".grounding.generic[0].snippets[0] | type"
# Returns: "string"

A test query returned 9 URLs with 19 total snippets of actual page content — all discarded by the current parsing logic.

Suggested Fix

Handle both strings and objects (in case Brave changes their API in the future):

snippets: (entry.snippets ?? []).map((s) => typeof s === "string" ? s : (s.text ?? "")).filter(Boolean)

Environment

  • OpenClaw 2026.3.8
  • Brave Search API with LLM Context endpoint (/res/v1/llm/context)
  • Config: tools.web.search.brave.mode: "llm-context"

Impact

The feature appears to work (no errors, results returned with titles and URLs) but provides zero value over standard web search mode since all extracted content is lost. Users have no indication anything is wrong.

extent analysis

Fix Plan

To fix the issue, update the runBraveLlmContextSearch function in src/agents/tools/web-search.ts to handle both string and object snippets:

  • Replace the existing snippets mapping logic with the following code:
snippets: (entry.snippets ?? []).map((s) => typeof s === "string" ? s : (s.text ?? "")).filter(Boolean)

This change will ensure that both plain string snippets and object snippets with a .text property are correctly parsed and included in the search results.

Verification

To verify the fix, perform the following steps:

  • Update the web-search.ts file with the new snippets mapping logic.
  • Run a test query using the Brave LLM Context API.
  • Check the search results for the presence of extracted page content in the snippets array.
  • Use a tool like curl and jq to inspect the API response and confirm that the snippets are being correctly parsed.

Extra Tips

  • Monitor the Brave LLM Context API for any changes to the snippet format.
  • Consider adding additional logging or error handling to detect and report any issues with snippet parsing.
  • Review the web-search.ts file for any other potential issues or areas for improvement.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING