tinyhumansai/openhuman · error
Brave returned malformed JSON: {e}
Error message
Brave returned malformed JSON: {e} What it means
The Brave API returned a 2xx response whose body could not be parsed as JSON in `brave_get`. This fires when the response body is not valid JSON at all — an HTML error/consent page from an intercepting proxy, a truncated body from a connection cut mid-transfer, or a content-type mismatch. It is distinct from a schema drift (fields missing/renamed), which is reported as a shape-changed error instead.
Source
Thrown at src/openhuman/search/tools/brave.rs:108
let detail = crate::openhuman::util::utf8_safe_prefix_at_byte_boundary(&body, 500);
tracing::warn!(
path = %path,
status = %status,
elapsed_ms = elapsed_ms as u64,
"[brave] non-2xx response: {detail}"
);
anyhow::bail!("Brave returned {status}: {detail}");
}
tracing::debug!(
path = %path,
status = %status,
elapsed_ms = elapsed_ms as u64,
body_bytes = body.len(),
"[brave] response ok"
);
serde_json::from_str::<Value>(&body).map_err(|e| {
tracing::warn!(path = %path, "[brave] JSON parse failed: {e}");
anyhow::anyhow!("Brave returned malformed JSON: {e}")
})
}
fn extract_query(args: &Value) -> anyhow::Result<String> {
let q = args
.get("query")
.and_then(|v| v.as_str())
.ok_or_else(|| anyhow::anyhow!("Missing required parameter: query"))?
.trim();
if q.is_empty() {
anyhow::bail!("Search query cannot be empty");
}
Ok(q.to_string())
}
fn clamped_count(args: &Value, default: usize, max: usize) -> usize {
args.get("count")
.and_then(|v| v.as_u64())View on GitHub (pinned to 7491200858)
Solutions
- Reproduce the raw response externally: `curl -H 'X-Subscription-Token: <key>' 'https://api.search.brave.com/res/v1/web/search?q=test'` to inspect what is actually returned
- If a corporate proxy intercepts TLS, configure the proxy or its CA in the core's TLS/proxy settings
- Retry once — truncated bodies from interrupted transfers are often transient
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at src/openhuman/search/tools/brave.rs:108 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of tinyhumansai/openhuman@7491200858 (2026-08-17).
Data as JSON: /api/errors/4eab121617e5426b.
Report an issue: GitHub.