fix(prompt): handle backend snake_case responses and fix endpoint routing#27
Open
definitelynotchirag wants to merge 4 commits into
Open
fix(prompt): handle backend snake_case responses and fix endpoint routing#27definitelynotchirag wants to merge 4 commits into
definitelynotchirag wants to merge 4 commits into
Conversation
…ting The Python SDK Prompt module had five bugs found during integration audit against the dev API: (1) template-by-name lookup used the labels endpoint instead of the name-only endpoint; (2) generate()/improve() crashed with KeyError because they assumed the async response contained a synchronous result; (3) delete() did not invalidate the cache, so subsequent lookups returned stale data; (4) several fields were read only in camelCase (templateVersion, isDefault, errorCode) but the backend returns snake_case; (5) the same pattern also reversed — some fields were read only in snake_case (prompt_config) but could arrive as camelCase from certain endpoints. All reads now try both casings, generate/improve use SimpleJsonResponseHandler with last_generation_id exposure, and endpoint URLs are corrected to the name-only routes.
The backend returns snake_case JSON consistently — no global camelCase middleware. The previous commit added dual-case reads defensively, but that just bloats the code. All reads now use snake_case keys only.
- Endpoint routing: verify get_template_by_name/delete_template_by_name use Routes.get_template_by_name, not label route - generate()/improve(): verify SimpleJsonResponseHandler, self-return, last_generation_id extraction, graceful missing-key handling - Cache invalidation: verify prompt_cache.invalidate(name) called on delete() and delete_template_by_name(), graceful on cache failure - snake_case keys: verify 'model' key, 'code' key, 'template_version' extraction throughout client.py and label_management.py
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.
What does this PR do?
Fixes the Python SDK Prompt module to correctly read snake_case keys returned by the backend, swaps two wrong endpoint URLs, and makes
generate()/improve()safe to call (removes broken synchronous result-assignment that crashed on async job responses).Why?
Five bugs were found during an integration audit against the dev API:
Routes.prompt_label_get_by_namewas used instead ofRoutes.get_template_by_name, causing 404s onget_template_by_name()anddelete_template_by_name().generate()/improve()crash — These calledresponse["result"]["prompt"]on an async job response that has nopromptkey, raisingKeyError. Replaced withSimpleJsonResponseHandlerand exposedlast_generation_idfor correlation; result is surfaced via the UI/job queue.get_template_by_name()afterdelete()returned the deleted template.template_version,is_default,is_draft,error_message,code). Several spots read only camelCase (templateVersion,isDefault,errorCode) or only snake_case, causing silent fallback to defaults.How was it tested?
python3 -m py_compilepasses on both modified filescurlcalls to the dev API to confirm backend response shapespytestorvitest)ruff check/mypy/npm run typecheck/npm run lintall passChecklist
mainfeat:,fix:,docs:,chore:…)docs/VOCABULARY.mdNotes for reviewers
The diff looks large because the model-config parsing pipeline was refactored from snake_case dict-literal keys to camelCase intermediary keys (matching what the backend returns), then mapped back to
ModelConfig's snake_case kwargs. This makes it obvious when a key isn't populated.