Langfuse Prompt Upsert
Create or update a Langfuse prompt and attach the development label.
- If the prompt does not exist: creates a new one (v1)
- If the prompt exists: creates a new version
Setup
Set the following environment variables before use:
| Variable | Required | Description |
|---|---|---|
LANGFUSE_PUBLIC_KEY | Yes | Langfuse public key |
LANGFUSE_SECRET_KEY | Yes | Langfuse secret key |
LANGFUSE_HOST or LANGFUSE_BASE_URL | No | Langfuse host URL (default: https://us.cloud.langfuse.com) |
When to Use
- Creating a new prompt
- Improving/updating an existing prompt
- Changing prompt content
Steps
1. Check Current Prompt (for updates)
npx tsx scripts/langfuse-prompt-view.ts <prompt-name> --label=development
2. Prepare New Prompt Content
Use AskUserQuestion to confirm or propose new prompt content.
3. Create/Update Prompt
Method A: Pipe directly (recommended)
cat << 'EOF' | npx tsx scripts/langfuse-prompt-upsert.ts <prompt-name>
Prompt content goes here...
EOF
Method B: Via file
# Save to /tmp/new-prompt.txt using the Write tool, then:
npx tsx scripts/langfuse-prompt-upsert.ts <prompt-name> /tmp/new-prompt.txt
4. Verify Result
npx tsx scripts/langfuse-prompt-view.ts <prompt-name> --label=development
Template Variables
Use $variableName format for dynamic values in prompts:
| Variable | Purpose |
|---|---|
$title | Title |
$content | Main content |
$searchResult | Search results |
$conversation | Conversation history |
$userQuestion | User's question |
Variables are replaced in code with .replace('$title', value).
Notes
- This skill only attaches the
developmentlabel - Attaching the
productionlabel should be done manually in the Langfuse UI - The existing
developmentlabel is automatically moved to the new version