crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] sanitize_tool_name exceeds short max_length limits

Open akkupratap323 opened this issue 1 month ago • 3 comments

Description

sanitize_tool_name(name, max_length=...) produces names longer than the requested limit when the limit is smaller than its nine-character hash suffix. Negative slice lengths preserve most of the original name before appending the suffix.

Steps to reproduce / code

On current main, Windows / Python 3.11:

from crewai.utilities.string_utils import sanitize_tool_name

for limit in (1, 4, 8, 9, 10, 64):
    result = sanitize_tool_name("fetch_customer_accounts", max_length=limit)
    print(limit, result, len(result))

Actual lengths: 23, 27, 31, 9, 10, 23 respectively. The first three exceed the explicit limit.

Expected behavior

For a positive limit, the result should fit that limit. Non-positive limits should be rejected clearly. The default 64-character behavior and existing readable-prefix/hash behavior for larger limits should remain unchanged.

Additional context

I reproduced this against the unchanged source module loaded with importlib.util; full-package regression validation is being prepared. No provider/network calls are needed. #7628 addresses empty sanitized names but leaves this truncation path unchanged, so it is a separate defect.

I can submit a focused fix using a truncated deterministic hash when there is insufficient room for the existing suffix, with regressions for short bounds and ordinary-name controls.

AI-generated contribution: investigated and implemented with Codex assistance. The required llm-generated label is requested for this issue and its PR.

akkupratap323 avatar Oct 13 '26 14:10 akkupratap323

The regression is confirmed using the installed local CrewAI packages: 11 tests fail on the original implementation, with five compatibility controls passing. After the scoped fix, the complete string utility file passes (28 tests). Could a maintainer apply the required llm-generated label? I requested it when creating the issue and tried adding it explicitly, but GitHub denies AddLabelsToLabelable for this account. The issue and upcoming PR explicitly disclose Codex assistance.

akkupratap323 avatar Oct 13 '26 15:10 akkupratap323

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 13 '26 12:11 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Nov 18 '26 12:11 github-actions[bot]