From 41bdb43db977c1c3000b7ed5769fc41eb2f9a50e Mon Sep 17 00:00:00 2001 From: Alexandr Smirnov Date: Mon, 1 Jun 2026 10:59:10 +0300 Subject: [PATCH] fix(ask_user_question): add minLength/maxLength to header JSON Schema Add minLength: 1 and maxLength: 12 constraints to the header property in the ask_user_question tool's JSON Schema. This prevents the LLM from generating headers longer than 12 characters before the tool call is made, reducing runtime rejections. Also adds a snapshot-style test that asserts the schema constraints are present, catching future regressions where the limits could be dropped. Runtime validation (lines 318-319) is kept as a safety net for callers that bypass the schema. --- .../core/src/tools/askUserQuestion.test.ts | 18 ++++++++++++++++++ packages/core/src/tools/askUserQuestion.ts | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/core/src/tools/askUserQuestion.test.ts b/packages/core/src/tools/askUserQuestion.test.ts index 63709baf93..e75ee56536 100644 --- a/packages/core/src/tools/askUserQuestion.test.ts +++ b/packages/core/src/tools/askUserQuestion.test.ts @@ -36,6 +36,24 @@ describe('AskUserQuestionTool', () => { }); }); + describe('JSON Schema', () => { + it('should enforce header maxLength 12 and minLength 1 in the schema', () => { + const schema = tool.schema.parametersJsonSchema as Record< + string, + unknown + >; + const questions = (schema['properties'] ?? {}) as Record; + const items = (questions['questions'] ?? {}) as Record; + const questionProps = (items['items'] ?? {}) as Record; + const header = (questionProps['properties'] ?? {}) as Record< + string, + unknown + >; + expect(header['maxLength']).toBe(12); + expect(header['minLength']).toBe(1); + }); + }); + describe('validateToolParams', () => { it('should accept valid params with single question', () => { const params = { diff --git a/packages/core/src/tools/askUserQuestion.ts b/packages/core/src/tools/askUserQuestion.ts index d6e571cf33..dafd017ce8 100644 --- a/packages/core/src/tools/askUserQuestion.ts +++ b/packages/core/src/tools/askUserQuestion.ts @@ -79,8 +79,10 @@ const askUserQuestionToolSchemaData: FunctionDeclaration = { }, header: { description: - 'Very short label displayed as a chip/tag (max 12 chars). Examples: "Auth method", "Library", "Approach".', + 'Required: 1-12 characters. Very short label displayed as a chip/tag. Examples: "Auth method", "Library", "Approach".', type: 'string', + minLength: 1, + maxLength: 12, }, options: { description: