[PR #20705] [MERGED] fix: coerce LLM tool call parameters to correct types in knowledge query #41369

Closed
opened 2026-04-25 13:37:30 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/20705
Author: @Classic298
Created: 1/15/2026
Status: Merged
Merged: 1/15/2026
Merged by: @tjbck

Base: devHead: fix-int


📝 Commits (1)

📊 Changes

1 file changed (+19 additions, -0 deletions)

View changed files

📝 backend/open_webui/tools/builtin.py (+19 -0)

📄 Description

fix: coerce LLM tool call parameters to correct types in knowledge query

Description

Fixes an issue where knowledge base queries would intermittently fail with "slice indices must be integers" errors.

Root Cause: When the LLM makes tool calls to query_knowledge_files, it sometimes formats parameters as strings instead of their proper types:

  • count as "5" instead of 5
  • knowledge_ids as "None" instead of null

This caused the slice operation in merge_and_sort_query_results to fail since you cannot slice a list with a string index.

Fix: Added type coercion at the start of query_knowledge_files to:

  • Convert count from string to int (with fallback to default)
  • Handle knowledge_ids being the literal strings "None", "null", or empty by converting to actual None
  • Parse knowledge_ids as JSON array if passed as a string representation

Closes #20704

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/20705 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 1/15/2026 **Status:** ✅ Merged **Merged:** 1/15/2026 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `fix-int` --- ### 📝 Commits (1) - [`1e0ab1d`](https://github.com/open-webui/open-webui/commit/1e0ab1dbc1f9a207a08978d0003bc7c343610142) Update builtin.py ### 📊 Changes **1 file changed** (+19 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/tools/builtin.py` (+19 -0) </details> ### 📄 Description ## fix: coerce LLM tool call parameters to correct types in knowledge query ### Description Fixes an issue where knowledge base queries would intermittently fail with "slice indices must be integers" errors. **Root Cause:** When the LLM makes tool calls to query_knowledge_files, it sometimes formats parameters as strings instead of their proper types: - count as "5" instead of 5 - knowledge_ids as "None" instead of null This caused the slice operation in merge_and_sort_query_results to fail since you cannot slice a list with a string index. **Fix:** Added type coercion at the start of query_knowledge_files to: - Convert count from string to int (with fallback to default) - Handle knowledge_ids being the literal strings "None", "null", or empty by converting to actual None - Parse knowledge_ids as JSON array if passed as a string representation Closes #20704 ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 13:37:30 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#41369