diff --git a/cron/brave_search.py b/cron/brave_search.py index c92875f..3196f76 100644 --- a/cron/brave_search.py +++ b/cron/brave_search.py @@ -59,8 +59,13 @@ async def _llm_filter(results: list[dict], criteria: str) -> list[dict]: data = resp.json() reply = data["choices"][0]["message"]["content"].strip() - # Parse the JSON array of indices - indices = json.loads(reply) + # Extract JSON array from response (LLM may include extra text) + import re + match = re.search(r"\[[\d,\s]*\]", reply) + if not match: + logger.warning("LLM filter returned no array: %s", reply) + return results + indices = json.loads(match.group()) if not isinstance(indices, list): logger.warning("LLM filter returned non-list: %s", reply) return results