fix(prompt-folders): update prompt in folder failed with wrong encoding #1335
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.
The httpx module encodes some special characters like "/", so this behaviour can bring some issues when managing prompts in folders.
Without parsing these characters on the prompt name, the
update_promptmethod would return an error.I have updated the method to parse the name so that the prompt name, if containing a "/" would be handled correctly in the API, and added an additional test to the prompt tests.
Important
Fix
update_promptinclient.pyto handle prompt names with slashes by URL encoding them, and add a test for prompts in folders.update_promptinclient.pyto handle prompt names with slashes by URL encoding them using_url_encode().test_update_prompt_in_folderintest_prompt.pyto verify correct handling of prompts in folders.This description was created by
for b66eef9. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Summary
Updated On: 2025-09-11 20:56:18 UTC
This PR fixes a critical bug in the
update_promptmethod where prompts organized in folder structures (with names containing forward slashes likefolder/prompt-name) would fail with 404 errors. The issue stemmed from the httpx library automatically URL-encoding special characters like/to%2F, causing the API to look for a prompt with the encoded name rather than the original name.The fix applies the existing
_url_encodemethod to the prompt name parameter before making the API call, ensuring consistent behavior with other prompt-related methods likeget_promptthat already handle URL encoding. The solution leverages the existing_url_encodeutility method (lines 2987-2998 in client.py) that properly handles httpx version compatibility and character escaping.A comprehensive test case
test_update_prompt_in_folderwas added to verify that prompts with folder-like names can be successfully created, retrieved, and updated. This test follows the same pattern as existing prompt tests but specifically validates the URL encoding fix by using a prompt name containing a forward slash.The change integrates seamlessly with the existing codebase by following established patterns for URL encoding in other API methods, ensuring consistency across the Langfuse client's prompt management functionality.
Confidence score: 4/5
_url_encodemethod implementation and the new test case validation