{"record":{"id":"7f8d62defb1ec7f6","repo":"sigoden/aichat","slug":"invalid-response-data-data-7f8d62","errorCode":null,"errorMessage":"Invalid response data: {data}","messagePattern":"Invalid response data: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/client/cohere.rs","lineNumber":245,"sourceCode":"            if let (Some(name), Some(arguments), Some(id)) = (\n                call[\"function\"][\"name\"].as_str(),\n                call[\"function\"][\"arguments\"].as_str(),\n                call[\"id\"].as_str(),\n            ) {\n                let arguments: Value = arguments.parse().with_context(|| {\n                    format!(\"Tool call '{name}' have non-JSON arguments '{arguments}'\")\n                })?;\n                tool_calls.push(ToolCall::new(\n                    name.to_string(),\n                    arguments,\n                    Some(id.to_string()),\n                ));\n            }\n        }\n    }\n\n    if text.is_empty() && tool_calls.is_empty() {\n        bail!(\"Invalid response data: {data}\");\n    }\n    let output = ChatCompletionsOutput {\n        text,\n        tool_calls,\n        id: data[\"id\"].as_str().map(|v| v.to_string()),\n        input_tokens: data[\"usage\"][\"billed_units\"][\"input_tokens\"].as_u64(),\n        output_tokens: data[\"usage\"][\"billed_units\"][\"output_tokens\"].as_u64(),\n    };\n    Ok(output)\n}\n","sourceCodeStart":227,"sourceCodeEnd":256,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/client/cohere.rs#L227-L256","documentation":"In the Cohere client's extract_chat_completions, the parsed response produced no text and no tool calls, so the library bails with 'Invalid response data' embedding the raw JSON. As with the other providers, an empty completion is treated as an invalid response rather than returned silently.","triggerScenarios":"chat_completions on Cohere receives a 2xx response whose generations/message fields yield empty text and no tool_calls — e.g. a safety-filtered generation, an empty generation, or an unexpected response schema (chat vs chat/v2 shapes).","commonSituations":"Cohere safety mode stripping output, wrong endpoint/version producing a schema the extractor doesn't understand, max_tokens too small, or model returning only finish reasons.","solutions":["Inspect {data} in the error for the actual Cohere response body and finish reasons","Check is_finished/finish_reason and safety fields in the payload","Increase max_tokens or adjust the prompt to avoid safety filtering","Confirm you are hitting the API version the library expects (Cohere v1 vs v2 schemas differ)","Update the library if Cohere changed its response schema"],"exampleFix":"// before\nclient.chat_completions(req).await?  // v2 endpoint, v1-shaped parser -> empty extract\n// after\n.with_provider(\"cohere/chat-v2\")  // or upgrade library so schema matches endpoint","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match client.chat_completions(req).await {\n    Err(e) if e.to_string().starts_with(\"Invalid response data\") => {\n        // inspect embedded Cohere JSON: finish_reason, safety flags\n        Err(anyhow!(\"cohere empty completion: {e}\"))\n    }\n    r => r,\n}","preventionTips":["Match the library version to the Cohere API version (v1 vs v2 schema)","Check finish_reason / safety-filter flags on empty generations","Avoid tiny max_tokens values","Review prompts that repeatedly trigger safety filtering"],"tags":["cohere","empty-response","api-response","parsing"],"backgroundTag":"empty-api-response","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}