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 <noreply@anthropic.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user