AgentV2 (dify-agent) sends empty-content system prompts and empty tool descriptions to Bedrock, causing ValidationException
- Dominant language
- TypeScript
- Stars
- 156k
- Forks
- 24.6k
- Avg merge
- 20h 50m
- Merged PRs (30d)
- 586
Description
### 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.16.0 (AgentV2 / dify-agent backend)
### Cloud or Self Hosted
Self Hosted (Docker)
### Steps to reproduce
1. Configure an AgentV2 (dify-agent) agent using an AWS Bedrock model (e.g. Anthropic Claude via Bedrock Converse API).
2. Attach one or more Skills to the agent, where at least one skill is **not** referenced/used in the current turn.
3. Run the agent so that a request is sent to Bedrock.
4. Bedrock rejects the request with a `ValidationException` because a text content block has empty content.
A related issue occurs when a tool used internally by dify-agent has no `description` set: dify-agent falls back to an empty string, which Bedrock also rejects for `toolSpec.description`.
### ✔️ Expected Behavior
- System prompt parts with empty/whitespace-only content (e.g. an unused skill's system prompt) should be filtered out before being sent to the model, consistent with how `_map_messages_to_prompt_messages` already filters empty instruction messages.
- Tool descriptions should never be sent as an empty string; if no description is provided, a non-empty fallback should be used.
### ❌ Actual Behavior
Bedrock rejects the request with a `ValidationException` for an empty text/description content block, and the agent run fails.
In `dify-agent/src/dify_agent/adapters/llm/model.py`:
1. `_map_model_request_to_prompt_messages()` appends a `SystemPromptMessage` for every `SystemPromptPart` unconditionally:
```python
if isinstance(part, SystemPromptPart):
prompt_messages.append(SystemPromptMessage(content=part.content))
```
Unlike `_map_messages_to_prompt_messages()`, which already filters `instruction_messages` with `if part.content.strip()`, this code path has no such check, so an empty-content `SystemPromptPart` (e.g. from an unreferenced skill) is forwarded as-is and Bedrock rejects it.
2. `_map_tool_definitions_to_prompt_tools()` builds `PromptMessageTool` with:
```python
description=tool_definition.description or "",
```
When an internal tool definition has no description, this defaults to an empty string, which Bedrock's Converse API also rejects for the `toolSpec.description` field.
Suggested fix: add the same `if part.content.strip()` guard to the `SystemPromptPart` branch in `_map_model_request_to_prompt_messages()` (skip appending when content is empty/whitespace-only), and fall back to `tool_definition.name` (or another non-empty placeholder) instead of `""` when `tool_definition.description` is falsy in `_map_tool_definitions_to_prompt_tools()`.
Currently working around this with a runtime patch applied to `dify_agent/adapters/llm/model.py` at container startup (`docker/docker-compose.override.yaml`), since no upstream fix exists yet.
Contributor guide
Research direction
Start in dify-agent/src/dify_agent/adapters/llm/model.py, reading _map_model_request_to_prompt_messages() and _map_tool_definitions_to_prompt_tools(). Verify the Bedrock request no longer receives empty or whitespace-only system prompt content or empty tool descriptions. The issue names no test file, so validate the behavior through the existing agent-to-Bedrock request path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- ai, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100