Tool call id length greater than 40 chars #20717

Closed
opened 2026-02-21 20:08:36 -05:00 by yindo · 5 comments
Owner

Originally created by @int-krishnaagrawal on GitHub (Dec 1, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.8.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Image

✔️ Expected Behavior

It should work.

Actual Behavior

It errored out.

Originally created by @int-krishnaagrawal on GitHub (Dec 1, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.8.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce <img width="455" height="189" alt="Image" src="https://github.com/user-attachments/assets/bbccbebb-8d07-433e-affc-4963a3927f81" /> ### ✔️ Expected Behavior It should work. ### ❌ Actual Behavior It errored out.
yindo added the 🐞 bug label 2026-02-21 20:08:36 -05:00
yindo closed this issue 2026-02-21 20:08:36 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Dec 1, 2025):

The 40-character limit for tool call IDs isn't enforced by Dify itself—it's imposed by the upstream LLM provider or plugin daemon. In Dify, tool call IDs are generated as UUIDs (36 characters), which fit within the limit, and there's no internal validation or configuration for this restriction in the codebase. If you use custom IDs, make sure they're trimmed to 40 characters or less before sending requests to the LLM API to avoid Bad Request errors. If you need to enforce this in Dify, you can add truncation logic where tool call IDs are generated (for example, in the agent runner code) source. For more details, check your LLM provider's documentation for their specific length restrictions.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Dec 1, 2025): <!-- Answer --> The 40-character limit for tool call IDs isn't enforced by Dify itself—it's imposed by the upstream LLM provider or plugin daemon. In Dify, tool call IDs are generated as UUIDs (36 characters), which fit within the limit, and there's no internal validation or configuration for this restriction in the codebase. If you use custom IDs, make sure they're trimmed to 40 characters or less before sending requests to the LLM API to avoid Bad Request errors. If you need to enforce this in Dify, you can add truncation logic where tool call IDs are generated (for example, in the agent runner code) [source](https://github.com/langgenius/dify/blob/0a22bc5d05160afa0334e620a333699af1e2e2c0/api/core/agent/base_agent_runner.py#L445-L475). For more details, check your LLM provider's documentation for their specific length restrictions. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/79b03342-2692-4b2d-bff9-c042661ae4b5?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/79b03342-2692-4b2d-bff9-c042661ae4b5?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/79b03342-2692-4b2d-bff9-c042661ae4b5?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/79b03342-2692-4b2d-bff9-c042661ae4b5?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/79b03342-2692-4b2d-bff9-c042661ae4b5?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/79b03342-2692-4b2d-bff9-c042661ae4b5?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/79b03342-2692-4b2d-bff9-c042661ae4b5?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%2040-character%20limit%20for%20tool%20call%20IDs%20isn%27t%20enforced%20by%20Dify%20itself%E2%80%94it%27s%20imposed%20by%20the%20upstream%20LLM%20provider%20or%20plugin%20daemon.%20In%20Dify%2C%20tool%20call%20IDs%20are%20generated%20as%20UUIDs%20%2836%20characters%29%2C%20which%20fit%20within%20the%20limit%2C%20and%20there%27s%20no%20internal%20validation%20or%20configuration%20for%20this%20restriction%20in%20the%20codebase.%20If%20you%20use%20custom%20IDs%2C%20make%20sure%20they%27re%20trimmed%20to%2040%20characters%20or%20less%20before%20sending%20requests%20to%20the%20LLM%20API%20to%20avoid%20Bad%20Request%20errors.%20If%20you%20need%20to%20enforce%20this%20in%20Dify%2C%20you%20can%20add%20truncation%20logic%20where%20tool%20call%20IDs%20are%20generated%20%28for%20example%2C%20in%20the%20agent%20runner%20code%29%20%5Bsource%5D%28https%3A//github.com/langgenius/dify/blob/0a22bc5d05160afa0334e620a333699af1e2e2c0/api/core/agent/base_agent_runner.py%23L445-L475%29.%20For%20more%20details%2C%20check%20your%20LLM%20provider%27s%20documentation%20for%20their%20specific%20length%20restrictions.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/28987)
Author
Owner

@int-krishnaagrawal commented on GitHub (Dec 1, 2025):

@dosu in my custom agent startegy, i am using
from dify_plugin.entities.agent import AgentInvokeMessage &
dify_plugin.entities.model.llm

the id is coming from these libraries.

@int-krishnaagrawal commented on GitHub (Dec 1, 2025): @dosu in my custom agent startegy, i am using `from dify_plugin.entities.agent import AgentInvokeMessage` & `dify_plugin.entities.model.llm` the id is coming from these libraries.
Author
Owner

@dosubot[bot] commented on GitHub (Dec 1, 2025):

Tool call IDs generated by dify_plugin.entities.model.llm (via the _gen_tool_call_id function) can exceed 40 characters—typically they're around 46 characters, like "chatcmpl-tool-" plus a 32-char UUID hex string. AgentInvokeMessage inherits its ID logic from ToolInvokeMessage and doesn't enforce any length limit either, so IDs from these libraries aren't automatically trimmed or validated for length. If your LLM provider requires IDs ≤ 40 characters, you'll need to intercept and truncate or regenerate them in your custom agent strategy before sending requests. For example:

def ensure_tool_call_id_length(tool_call_id: str, max_length: int = 40) -> str:
    return tool_call_id[:max_length]

# When creating or updating AgentInvokeMessage:
msg.id = ensure_tool_call_id_length(msg.id)

Make sure all tool call IDs are strings and fit the required length for your provider to avoid Bad Request errors. If you need help pinpointing where to apply this in your workflow, let me know!
Source: ID generation logic

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Dec 1, 2025): <!-- Answer --> Tool call IDs generated by dify_plugin.entities.model.llm (via the _gen_tool_call_id function) can exceed 40 characters—typically they're around 46 characters, like "chatcmpl-tool-" plus a 32-char UUID hex string. AgentInvokeMessage inherits its ID logic from ToolInvokeMessage and doesn't enforce any length limit either, so IDs from these libraries aren't automatically trimmed or validated for length. If your LLM provider requires IDs ≤ 40 characters, you'll need to intercept and truncate or regenerate them in your custom agent strategy before sending requests. For example: ```python def ensure_tool_call_id_length(tool_call_id: str, max_length: int = 40) -> str: return tool_call_id[:max_length] # When creating or updating AgentInvokeMessage: msg.id = ensure_tool_call_id_length(msg.id) ``` Make sure all tool call IDs are strings and fit the required length for your provider to avoid Bad Request errors. If you need help pinpointing where to apply this in your workflow, let me know! [Source: ID generation logic](https://github.com/langgenius/dify/blob/0a22bc5d05160afa0334e620a333699af1e2e2c0/api/core/model_runtime/model_providers/__base/large_language_model.py#L29-L238) <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/e581a8ae-abc9-4287-816a-6d2184b2cbed?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/e581a8ae-abc9-4287-816a-6d2184b2cbed?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/e581a8ae-abc9-4287-816a-6d2184b2cbed?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/e581a8ae-abc9-4287-816a-6d2184b2cbed?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/e581a8ae-abc9-4287-816a-6d2184b2cbed?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/e581a8ae-abc9-4287-816a-6d2184b2cbed?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/e581a8ae-abc9-4287-816a-6d2184b2cbed?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Tool%20call%20IDs%20generated%20by%20dify_plugin.entities.model.llm%20%28via%20the%20_gen_tool_call_id%20function%29%20can%20exceed%2040%20characters%E2%80%94typically%20they%27re%20around%2046%20characters%2C%20like%20%22chatcmpl-tool-%22%20plus%20a%2032-char%20UUID%20hex%20string.%20AgentInvokeMessage%20inherits%20its%20ID%20logic%20from%20ToolInvokeMessage%20and%20doesn%27t%20enforce%20any%20length%20limit%20either%2C%20so%20IDs%20from%20these%20libraries%20aren%27t%20automatically%20trimmed%20or%20validated%20for%20length.%20If%20your%20LLM%20provider%20requires%20IDs%20%E2%89%A4%2040%20characters%2C%20you%27ll%20need%20to%20intercept%20and%20truncate%20or%20regenerate%20them%20in%20your%20custom%20agent%20strategy%20before%20sending%20requests.%20For%20example%3A%0A%0A%60%60%60python%0Adef%20ensure_tool_call_id_length%28tool_call_id%3A%20str%2C%20max_length%3A%20int%20%3D%2040%29%20-%3E%20str%3A%0A%20%20%20%20return%20tool_call_id%5B%3Amax_length%5D%0A%0A%23%20When%20creating%20or%20updating%20AgentInvokeMessage%3A%0Amsg.id%20%3D%20ensure_tool_call_id_length%28msg.id%29%0A%60%60%60%0A%0AMake%20sure%20all%20tool%20call%20IDs%20are%20strings%20and%20fit%20the%20required%20length%20for%20your%20provider%20to%20avoid%20Bad%20Request%20errors.%20If%20you%20need%20help%20pinpointing%20where%20to%20apply%20this%20in%20your%20workflow%2C%20let%20me%20know%21%20%20%0A%5BSource%3A%20ID%20generation%20logic%5D%28https%3A//github.com/langgenius/dify/blob/0a22bc5d05160afa0334e620a333699af1e2e2c0/api/core/model_runtime/model_providers/__base/large_language_model.py%23L29-L238%29)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/28987)
Author
Owner

@int-krishnaagrawal commented on GitHub (Dec 1, 2025):

@dosu but is it safe to truncate the id, can it break the flow anyhow?

@int-krishnaagrawal commented on GitHub (Dec 1, 2025): @dosu but is it safe to truncate the id, can it break the flow anyhow?
Author
Owner

@dosubot[bot] commented on GitHub (Dec 1, 2025):

It's not safe to simply truncate tool call IDs in Dify. These IDs are used as unique keys to match tool calls and responses throughout the agent workflow, using exact string equality. If you truncate an ID, you risk collisions or mismatches, which can break the flow—responses might not be matched to the correct tool call, and internal state updates could fail or go to the wrong place. There is no built-in protection against this in the codebase, so truncating without ensuring uniqueness and updating all references can definitely cause issues (source).

The best practice is to generate unique IDs that are within the required length limit from the start. For example, you can use a shortened UUID or a base64-encoded random string:

import uuid

def short_tool_call_id(max_length=40):
    # 32 chars from uuid4 hex, optionally add a short prefix
    return uuid.uuid4().hex[:max_length]

# Usage:
msg.id = short_tool_call_id()

If you must truncate, make sure the truncated ID is still unique within the context of the conversation and that every part of your workflow uses the truncated form consistently. Otherwise, you risk breaking tool call tracking and response mapping. If you want help designing a safe ID generation strategy for your use case, let me know!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Dec 1, 2025): <!-- Answer --> It's not safe to simply truncate tool call IDs in Dify. These IDs are used as unique keys to match tool calls and responses throughout the agent workflow, using exact string equality. If you truncate an ID, you risk collisions or mismatches, which can break the flow—responses might not be matched to the correct tool call, and internal state updates could fail or go to the wrong place. There is no built-in protection against this in the codebase, so truncating without ensuring uniqueness and updating all references can definitely cause issues ([source](https://github.com/langgenius/dify/blob/0a22bc5d05160afa0334e620a333699af1e2e2c0/api/core/model_runtime/model_providers/__base/large_language_model.py#L29-L79)). The best practice is to generate unique IDs that are within the required length limit from the start. For example, you can use a shortened UUID or a base64-encoded random string: ```python import uuid def short_tool_call_id(max_length=40): # 32 chars from uuid4 hex, optionally add a short prefix return uuid.uuid4().hex[:max_length] # Usage: msg.id = short_tool_call_id() ``` If you must truncate, make sure the truncated ID is still unique within the context of the conversation and that every part of your workflow uses the truncated form consistently. Otherwise, you risk breaking tool call tracking and response mapping. If you want help designing a safe ID generation strategy for your use case, let me know! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/fc0a3e5e-939d-41c9-9f12-ee910f05ab6e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/fc0a3e5e-939d-41c9-9f12-ee910f05ab6e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/fc0a3e5e-939d-41c9-9f12-ee910f05ab6e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/fc0a3e5e-939d-41c9-9f12-ee910f05ab6e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/fc0a3e5e-939d-41c9-9f12-ee910f05ab6e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/fc0a3e5e-939d-41c9-9f12-ee910f05ab6e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/fc0a3e5e-939d-41c9-9f12-ee910f05ab6e?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=It%27s%20not%20safe%20to%20simply%20truncate%20tool%20call%20IDs%20in%20Dify.%20These%20IDs%20are%20used%20as%20unique%20keys%20to%20match%20tool%20calls%20and%20responses%20throughout%20the%20agent%20workflow%2C%20using%20exact%20string%20equality.%20If%20you%20truncate%20an%20ID%2C%20you%20risk%20collisions%20or%20mismatches%2C%20which%20can%20break%20the%20flow%E2%80%94responses%20might%20not%20be%20matched%20to%20the%20correct%20tool%20call%2C%20and%20internal%20state%20updates%20could%20fail%20or%20go%20to%20the%20wrong%20place.%20There%20is%20no%20built-in%20protection%20against%20this%20in%20the%20codebase%2C%20so%20truncating%20without%20ensuring%20uniqueness%20and%20updating%20all%20references%20can%20definitely%20cause%20issues%C2%A0%28%5Bsource%5D%28https%3A//github.com/langgenius/dify/blob/0a22bc5d05160afa0334e620a333699af1e2e2c0/api/core/model_runtime/model_providers/__base/large_language_model.py%23L29-L79%29%29.%0A%0AThe%20best%20practice%20is%20to%20generate%20unique%20IDs%20that%20are%20within%20the%20required%20length%20limit%20from%20the%20start.%20For%20example%2C%20you%20can%20use%20a%20shortened%20UUID%20or%20a%20base64-encoded%20random%20string%3A%0A%0A%60%60%60python%0Aimport%20uuid%0A%0Adef%20short_tool_call_id%28max_length%3D40%29%3A%0A%20%20%20%20%23%2032%20chars%20from%20uuid4%20hex%2C%20optionally%20add%20a%20short%20prefix%0A%20%20%20%20return%20uuid.uuid4%28%29.hex%5B%3Amax_length%5D%0A%0A%23%20Usage%3A%0Amsg.id%20%3D%20short_tool_call_id%28%29%0A%60%60%60%0A%0AIf%20you%20must%20truncate%2C%20make%20sure%20the%20truncated%20ID%20is%20still%20unique%20within%20the%20context%20of%20the%20conversation%20and%20that%20every%20part%20of%20your%20workflow%20uses%20the%20truncated%20form%20consistently.%20Otherwise%2C%20you%20risk%20breaking%20tool%20call%20tracking%20and%20response%20mapping.%20If%20you%20want%20help%20designing%20a%20safe%20ID%20generation%20strategy%20for%20your%20use%20case%2C%20let%20me%20know%21)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/28987)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#20717