You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
match serde_json::from_str::<serde_json::Value>(s){
111
-
Ok(_) => std::mem::take(s),
112
-
Err(e) => {
113
-
// Try permissive json5 parsing as fallback
114
-
match json5::from_str::<serde_json::Value>(s){
115
-
Ok(value) => {
116
-
println!("[Anthropic] Used permissive JSON5 parser for output");
117
-
serde_json::to_string(&value)?
118
-
},
119
-
Err(e2) => returnErr(anyhow::anyhow!(format!("No structured tool output or text found in response, and permissive JSON5 parsing also failed: {e}; {e2}")))
120
-
}
121
-
}
122
-
}
123
-
}
124
-
_ => {
125
-
returnErr(anyhow::anyhow!(
126
-
"No structured tool output or text found in response"
127
-
))
128
-
}
129
-
}
82
+
// Extract the text response
83
+
let text = match resp_json["content"][0]["text"].as_str(){
84
+
Some(s) => s.to_string(),
85
+
None => bail!("No text in response"),
130
86
};
131
87
132
-
Ok(LlmGenerateResponse{ text })
88
+
// Try to parse as JSON
89
+
match serde_json::from_str::<serde_json::Value>(&text){
// Only import this in clients that require strict JSON output instructions (e.g., Anthropic, Gemini, Ollama)
3
+
4
+
pubconstSTRICT_JSON_PROMPT:&str = "IMPORTANT: Output ONLY valid JSON that matches the schema. Do NOT say anything else. Do NOT explain. Do NOT preface. Do NOT add comments. If you cannot answer, output an empty JSON object: {}.";
0 commit comments