Skip to content

Add upper bound validation for AI response length#146

Merged
DimaBir merged 5 commits into
dimabir/github_bot_respond_wikifrom
copilot/sub-pr-144-again
Feb 11, 2026
Merged

Add upper bound validation for AI response length#146
DimaBir merged 5 commits into
dimabir/github_bot_respond_wikifrom
copilot/sub-pr-144-again

Conversation

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Addresses feedback from #144: the max_tokens increase to 800 lacked corresponding response length validation, allowing responses to exceed the "50-150 words" guidance.

Changes

  • Added validation constants: MIN_AI_RESPONSE_LENGTH (20) and MAX_AI_RESPONSE_LENGTH (1000)
  • Implemented max length check: Rejects responses >1000 chars (~150 words + 250 char buffer for markdown/links)
  • Optimized validation: Single trim operation, reused across both min/max checks
  • Improved observability: Both validation failures now log actual vs expected character counts
// Response validation constants
const MIN_AI_RESPONSE_LENGTH = 20;
const MAX_AI_RESPONSE_LENGTH = 1000; // ~150 words (~750 chars) + 250 char buffer for markdown

// Trim response once for validation
const trimmedResponse = aiResponse ? aiResponse.trim() : '';

if (!trimmedResponse || trimmedResponse.length < MIN_AI_RESPONSE_LENGTH) {
  console.log(`::warning::AI response too short (${trimmedResponse.length} chars, min ${MIN_AI_RESPONSE_LENGTH})`);
  // ... error handling
}

if (trimmedResponse.length > MAX_AI_RESPONSE_LENGTH) {
  console.log(`::warning::AI response too long (${trimmedResponse.length} chars, max ${MAX_AI_RESPONSE_LENGTH})`);
  // ... error handling
}

Responses exceeding the limit are rejected rather than truncated to maintain quality and enforce conciseness.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits February 11, 2026 07:10
Co-authored-by: DimaBir <28827735+DimaBir@users.noreply.github.com>
Co-authored-by: DimaBir <28827735+DimaBir@users.noreply.github.com>
Co-authored-by: DimaBir <28827735+DimaBir@users.noreply.github.com>
Co-authored-by: DimaBir <28827735+DimaBir@users.noreply.github.com>
Copilot AI changed the title [WIP] Update assistant workflow for rate limits and state management Add upper bound validation for AI response length Feb 11, 2026
Copilot AI requested a review from DimaBir February 11, 2026 07:15
@DimaBir DimaBir marked this pull request as ready for review February 11, 2026 07:17
@DimaBir DimaBir merged commit 9040f8b into dimabir/github_bot_respond_wiki Feb 11, 2026
1 check passed
@DimaBir DimaBir deleted the copilot/sub-pr-144-again branch February 11, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants