mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix(backend): validate non-empty question in ask_question tool
Reject empty/whitespace-only question strings with ValueError instead of producing an empty clarification card.
This commit is contained in:
@@ -68,7 +68,10 @@ class AskQuestionTool(BaseTool):
|
||||
**kwargs: Any,
|
||||
) -> ToolResponseBase:
|
||||
del user_id # unused; required by BaseTool contract
|
||||
question: str = kwargs.get("question", "")
|
||||
question_raw = kwargs.get("question")
|
||||
if not isinstance(question_raw, str) or not question_raw.strip():
|
||||
raise ValueError("ask_question requires a non-empty 'question' string")
|
||||
question = question_raw.strip()
|
||||
options: list[str] = kwargs.get("options", [])
|
||||
keyword: str = kwargs.get("keyword", "")
|
||||
session_id = session.session_id if session else None
|
||||
|
||||
@@ -69,3 +69,14 @@ async def test_execute_with_keyword_only(tool: AskQuestionTool, session: ChatSes
|
||||
q = result.questions[0]
|
||||
assert q.keyword == "trigger"
|
||||
assert q.example is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_execute_rejects_empty_question(
|
||||
tool: AskQuestionTool, session: ChatSession
|
||||
):
|
||||
with pytest.raises(ValueError, match="non-empty"):
|
||||
await tool._execute(user_id=None, session=session, question="")
|
||||
|
||||
with pytest.raises(ValueError, match="non-empty"):
|
||||
await tool._execute(user_id=None, session=session, question=" ")
|
||||
|
||||
Reference in New Issue
Block a user