MCPcopy Create free account
hub / github.com/InfinitiBit/graphbit / parse_json_string_array

Function parse_json_string_array

core/src/memory/processor.rs:142–163  ·  view source on GitHub ↗

Parse a JSON array of strings from potentially messy LLM output.

(text: &str)

Source from the content-addressed store, hash-verified

140
141/// Parse a JSON array of strings from potentially messy LLM output.
142fn parse_json_string_array(text: &str) -> GraphBitResult<Vec<String>> {
143 // Try to find the JSON array in the response.
144 let trimmed = text.trim();
145
146 // First try direct parse.
147 if let Ok(arr) = serde_json::from_str::<Vec<String>>(trimmed) {
148 return Ok(arr);
149 }
150
151 // Try to extract the first JSON array from the text.
152 if let Some(start) = trimmed.find('[') {
153 if let Some(end) = trimmed.rfind(']') {
154 let slice = &trimmed[start..=end];
155 if let Ok(arr) = serde_json::from_str::<Vec<String>>(slice) {
156 return Ok(arr);
157 }
158 }
159 }
160
161 // Fallback: return empty array if we can't parse.
162 Ok(Vec::new())
163}
164
165/// Parse the decision JSON from the LLM response.
166fn parse_decisions(text: &str) -> GraphBitResult<Vec<MemoryDecision>> {

Callers 1

extract_factsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected