fix: handle empty response in forced rewrite function

- Updated the `_forced_rewrite` function to strip whitespace from the extracted text and added a warning log if the response is empty, preventing potential issues with empty rewrites.
This commit is contained in:
Anish Sarkar 2026-05-04 12:18:09 +05:30
parent b981b51ab1
commit e38e20b484

View file

@ -189,8 +189,11 @@ async def _forced_rewrite(content: str, llm: Any) -> str | None:
[HumanMessage(content=prompt)],
config={"tags": ["surfsense:internal"]},
)
text = extract_text_content(response.content)
return text.strip()
text = extract_text_content(response.content).strip()
if not text:
logger.warning("Forced rewrite returned empty text; aborting rewrite")
return None
return text
except Exception:
logger.exception("Forced rewrite LLM call failed")
return None