Skip to content

feat: add prompt variable compilation#28

Open
ChoMinGi wants to merge 1 commit intolangfuse:mainfrom
ChoMinGi:feat/prompt-compilation
Open

feat: add prompt variable compilation#28
ChoMinGi wants to merge 1 commit intolangfuse:mainfrom
ChoMinGi:feat/prompt-compilation

Conversation

@ChoMinGi
Copy link
Copy Markdown

@ChoMinGi ChoMinGi commented Mar 23, 2026

Summary

Adds PromptTemplate and PromptCompiler under com.langfuse.client.prompt — no changes to Fern-generated code.

PromptTemplate handles {{var}} replacement and variable extraction. PromptCompiler wraps it for TextPrompt and ChatPrompt types so the usage feels similar to the Python/JS SDKs.
Tests cover basic replacement, missing/extra vars, null handling, edge cases for both text and chat prompts.

Closes #13

Scope

  • Text prompt compilation
  • Chat prompt compilation (per-message variable substitution)
  • PlaceholderMessage expansion (inserting message lists at placeholder positions) — not included in this PR, planned as a follow-up

Test plan

  • 20 unit tests for PromptTemplate (basic replacement, missing/extra vars, null handling, whitespace, edge cases)
  • 5 unit tests for PromptCompiler (text prompt, chat prompt, placeholder skipping, empty prompt)

Add PromptTemplate and PromptCompiler utilities for {{variable}}
template compilation, matching the Python/JS SDK compile() behavior.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 23, 2026

CLA assistant check
All committers have signed the CLA.

@ChoMinGi ChoMinGi marked this pull request as ready for review March 24, 2026 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle prompt variables

2 participants