Repository navigation
Conversation
ChatPromptClient exposes chat messages with type="message", and create_prompt is typed to accept that shape through ChatMessageWithPlaceholdersDict. The generated API models only allow "chatmessage" for that field, so passing a fetched prompt's .prompt to create_prompt raised a ValidationError for CreateChatPromptRequest before any request was sent. get_prompt failed the same way when such a list was given as a chat fallback, raising inside the fetch error path instead of returning the fallback. Map type="message" to "chatmessage" before building the request and the fallback Prompt_Chat. Placeholders and messages without a type key are passed through unchanged, and the caller's list is not modified.
|
|
6 of 11 tasks
This branch has not been deployed
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?
ChatPromptClient.promptreturns chat messages as{"type": "message", "role": ..., "content": ...}, andcreate_promptis typed to accept exactly that shape (ChatMessageWithPlaceholdersDict_Message). The generatedChatMessagemodel only allows"chatmessage"fortype, though, so feeding a fetched chat prompt back intocreate_promptfails before anything is sent.Copying a chat prompt under a new name shows it. I reproduced it with an httpx MockTransport, so no server was involved.
On main this raises
ValidationError: 3 validation errors for CreateChatPromptRequest ... Input should be 'chatmessage' [type=enum, input_value='message', input_type=str]. Building theChatMessageWithPlaceholdersDict_MessageTypedDict by hand fails the same way. Messages without atypekey work, which is probably why it went unnoticed.get_prompt(..., type="chat", fallback=...)has the same problem when the fallback list carriestype: "message". It raisesValidationError: 3 validation errors for Prompt_Chatwith the same message inside the fetch error handler, so the caller gets an exception instead of the fallback. I knowfallbackis typed asList[ChatMessageDict], which has notypekey. But a fallback that includes a placeholder has to usetypekeys, and anyone following the SDK's ownChatMessageWithPlaceholdersDictwrites"message"for the regular entries. If you would rather keepfallbackstrict, that part can be dropped and thecreate_promptfix stands on its own.The fix adds a small helper in
client.pythat copies any dict withtype == "message"and sets"chatmessage"instead. Placeholders, messages without atypeand pydantic message objects are left as they are, and the caller's list is not mutated. It runs increate_promptbeforeCreateChatPromptRequestand on the chat fallback beforePrompt_Chat. Nothing inlangfuse/api/was touched.Type of change
Verification
I added two unit tests to
tests/unit/test_prompt.py. One creates a prompt from a fetchedChatPromptClientand checks that the request carrieschatmessageandplaceholderentries. The other passes atype: "message"fallback while the fetch fails and checks that it comes back withis_fallbackset and compiles. On main they fail with theCreateChatPromptRequestandPrompt_Chaterrors quoted above, and with the change they pass.I ran everything in the project venv (Python 3.14.4, ruff 0.15.7, mypy 1.19.1) with the
LANGFUSE_*values from the CI workflow exported, since thelangfusefixture intest_prompt.pyneeds them (#1976).I did not run the e2e suite because it needs a running Langfuse server, and I only ran the tests on Python 3.14.
Checklist
code_review.md..env.templateif needed.

Confidence Score: 5/5
This PR appears safe to merge.Summary
Converts chat dictionaries from
type="message"to the API’stype="chatmessage"before creating prompts or building fallbacks.Acknowledgment: v0ropaev noted that the existing
fallbackannotation excludes placeholders; this known limitation was not reported again.Reviews (1) · Last reviewed commit: "fix(prompts): accept fetched chat messag..." · Reviewed by Greptile