fix(adapters): PromptTool returns string instead of raw PromptMessage list#1622
Open
sanmay-codes wants to merge 1 commit into
Open
fix(adapters): PromptTool returns string instead of raw PromptMessage list#1622sanmay-codes wants to merge 1 commit into
sanmay-codes wants to merge 1 commit into
Conversation
…lidationException When a PromptTool is called, _arun returns result.messages directly — a list of PromptMessage objects. LangGraph wraps this in a ToolMessage with content=[], which AWS Bedrock rejects with: ValidationException: tool_use ids found without tool_result blocks immediately after Fix: convert result.messages to a plain string. Empty message lists return the '(no prompt content)' placeholder so Bedrock always receives a non-empty string. Relates to mcp-use#1604
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
`PromptTool._arun` returns `result.messages` directly — a `list[PromptMessage]`. LangGraph wraps this in a `ToolMessage` with `content=[]` (empty list), which AWS Bedrock rejects with:
```
ValidationException: tool_use ids found without tool_result blocks immediately after
```
This affects any MCP server that exposes a prompt alongside a tool with the same name (e.g. Enterpret's `initialize_wisdom`). The LLM calls the prompt tool, gets back an empty list, and Bedrock rejects the next message as malformed.
This is a companion fix to #1620 — that PR addresses `CallToolResult.content=[]` in regular tools; this PR addresses the same class of bug in prompt tools.
Closes #1621
Fix
Convert `result.messages` to a plain string before returning, so LangGraph always creates a `ToolMessage` with non-empty string content:
```python
Before
return result.messages
After
if not result.messages:
return "(no prompt content)"
return "\n".join(str(m.content) for m in result.messages)
```
Testing
Verified end-to-end with: