{"record":{"id":"537d6f09c06a4067","repo":"xai-org/grok-build","slug":"failed-to-build-request-e-537d6f","errorCode":null,"errorMessage":"Failed to build request: {e}","messagePattern":"Failed to build request: (.+?)","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-tools/src/implementations/web_search/client.rs","lineNumber":165,"sourceCode":"            xai_tool_runtime::ToolError::execution(\n                xai_tool_protocol::ToolId::new(\"web_search\").expect(\"valid\"),\n                msg,\n            )\n        };\n        let web_search = rs::WebSearchToolArgs::default()\n            .filters(rs::WebSearchToolFilters { allowed_domains })\n            .build()\n            .map_err(|e| err(format!(\"Failed to build web search tool: {e}\")))?;\n        let request = rs::CreateResponseArgs::default()\n            .model(self.model.clone())\n            .input(query.to_string())\n            .tools(vec![rs::Tool::WebSearch(web_search)])\n            .store(false)\n            .temperature(0.1)\n            .top_p(0.95)\n            .max_output_tokens(8192u32)\n            .build()\n            .map_err(|e| err(format!(\"Failed to build request: {e}\")))?;\n        let mut body = serde_json::to_value(&request)\n            .map_err(|e| err(format!(\"Failed to serialize request: {e}\")))?;\n        if let Some(excluded) = excluded_domains.filter(|d| !d.is_empty()) {\n            let tool = body\n                .get_mut(\"tools\")\n                .and_then(|t| t.as_array_mut())\n                .and_then(|arr| arr.first_mut())\n                .and_then(|t| t.as_object_mut());\n            if let Some(tool) = tool {\n                let filters = tool\n                    .entry(\"filters\")\n                    .or_insert_with(|| serde_json::json!({}));\n                filters[\"excluded_domains\"] = serde_json::json!(excluded);\n            }\n        }\n        Ok(body)\n    }\n    /// Wire a 401-attribution callback into this client. Idempotent;","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-tools/src/implementations/web_search/client.rs#L147-L183","documentation":"After the web search tool is built, the client assembles the full responses-API request (model, input, tools, temperature, top_p, max_output_tokens) via CreateResponseArgs and calls .build(). If the builder rejects the assembled arguments it maps the error to \"Failed to build request: {e}\". This is a client-side request construction failure; no request ever reaches the network.","triggerScenarios":"Calling search/search_with_titles with a model the builder deems invalid, or argument combinations the rs crate's CreateResponseArgs rejects (e.g. invalid max_output_tokens, mutually inconsistent fields, or a crate version where a previously optional field is now required).","commonSituations":"Configured model name is empty or unsupported after an API update; upgrading the rs crate changed builder invariants; programmatic callers overriding model with a bad value from config/env.","solutions":["Read the wrapped {e} message to identify which builder field was rejected.","Verify self.model is a valid, non-empty model identifier supported by the responses API.","Check the rs crate changelog for CreateResponseArgs changes and update the construction accordingly.","Build a minimal request (model + input + tool only) to isolate which optional field triggers the failure."],"exampleFix":"// before\nlet client = WebSearchClient::new(\"\")?; // empty model\n// after\nlet client = WebSearchClient::new(\"gpt-4o\")?; // valid model id","handlingStrategy":"validation","validationCode":"function validateSearchRequestArgs(model) {\n  if (typeof model !== 'string' || model.trim().length === 0) {\n    throw new Error('search requires a non-empty model identifier');\n  }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n  result = await client.search(query);\n} catch (e) {\n  if (String(e).startsWith('Failed to build request')) {\n    // surface the wrapped builder message to config owners\n    throw new Error('Web search request config invalid: ' + e.message);\n  } else { throw e; }\n}","preventionTips":["Keep the model identifier in validated configuration; reject empty/unknown values at startup.","Test request construction with a minimal args set in CI after every rs crate upgrade.","Read the rs crate changelog for CreateResponseArgs breaking changes before upgrading."],"tags":["web-search","request-building","validation"],"backgroundTag":"request-build-validation-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}