From 5c043b76b66c03c324b918fe9ecd2d5599288dc6 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sat, 28 Feb 2026 20:01:43 -0500 Subject: [PATCH] Validate create_note/create_task title is a string before DB insert The model occasionally passes title as a list (e.g. when asked to create multiple notes at once), causing asyncpg DataError on the INSERT. Return a clear error result so the model sees the problem and retries with individual calls instead of crashing with an unhandled exception. Co-Authored-By: Claude Sonnet 4.6 --- src/fabledassistant/services/tools.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/fabledassistant/services/tools.py b/src/fabledassistant/services/tools.py index 0810239..85db213 100644 --- a/src/fabledassistant/services/tools.py +++ b/src/fabledassistant/services/tools.py @@ -740,6 +740,10 @@ async def execute_tool(user_id: int, tool_name: str, arguments: dict) -> dict: if tool_name == "create_task": task_title = arguments.get("title", "Untitled Task") task_body = arguments.get("body", "") + if not isinstance(task_title, str): + return {"success": False, "error": "title must be a string. Call create_task once per task."} + if not isinstance(task_body, str): + task_body = "" note = await create_note( user_id=user_id, title=task_title, @@ -767,6 +771,12 @@ async def execute_tool(user_id: int, tool_name: str, arguments: dict) -> dict: note_title = arguments.get("title", "Untitled Note") note_body = arguments.get("body", "") note_tags = arguments.get("tags", []) + if not isinstance(note_title, str): + return {"success": False, "error": "title must be a string. Call create_note once per note."} + if not isinstance(note_body, str): + note_body = "" + if not isinstance(note_tags, list): + note_tags = [] note = await create_note( user_id=user_id, title=note_title,