Implementation:Helicone Helicone Perform Edit Prompt
| Knowledge Sources | |
|---|---|
| Domains | Prompt Engineering, LLM Integration |
| Last Updated | 2026-02-14 06:32 GMT |
Overview
Generates structured LLM prompt messages for performing targeted edits on prompt text, along with contextual edit suggestion definitions.
Description
This module provides two key exports for the prompt playground's natural language editing feature:
performEditPrompt Function: Generates a three-part prompt structure (system, user, prefill) for instructing an LLM to apply targeted edits to a specific section of prompt text. The system message establishes the LLM as a "world-class prompt editor" with the edit goal. The user message provides the surrounding context with the edit target marked using XML-like tags. The prefill message starts the response with an <edited_target> tag to constrain the output format.
suggestions Array: Defines four pre-configured edit suggestion types, each with a label, a detailed goal description, and a condition function that returns a relevance weight:
- Synonym (weight 3 for 1-2 word selections): Replaces words with more suitable alternatives while matching formality, preserving technical accuracy, and ensuring semantic equivalence.
- Clarity (weight based on complex words and long sentences): Enhances comprehension by simplifying phrases, using consistent terminology, and restructuring for logical flow.
- Shorten (weight 2 for text over 100 characters): Increases impact through concision by eliminating redundancy and removing qualifier words.
- Lengthen (weight 2 for text under 100 characters): Enriches content by adding context, examples, explanations, and supporting evidence.
The condition functions use heuristics (word count, word length, sentence length, character count) to determine which suggestions are most relevant for a given text selection.
Usage
Use performEditPrompt when implementing the prompt playground's "edit with natural language" feature. Use the suggestions array to populate context-sensitive edit suggestion buttons based on the user's text selection.
Code Reference
Source Location
- Repository: Helicone
- File: web/prompts/perform-edit.ts
Signature
export default function performEditPrompt(
editGoal: string,
editTarget: string,
contextBefore: string,
contextAfter: string,
): { system: string; user: string; prefill: string };
export const suggestions: Array<{
label: string;
goal: string;
condition: (text: string) => number;
}>;
Import
import performEditPrompt, { suggestions } from "@/prompts/perform-edit";
I/O Contract
performEditPrompt Parameters
| Parameter | Type | Description |
|---|---|---|
| editGoal | string |
The user's instruction for what edit to apply (e.g., "Make it more concise") |
| editTarget | string |
The specific text segment to be edited |
| contextBefore | string |
Text appearing before the edit target for context |
| contextAfter | string |
Text appearing after the edit target for context |
performEditPrompt Return Value
| Property | Type | Description |
|---|---|---|
| system | string |
System prompt establishing the editor role and edit goal |
| user | string |
User message with context and edit target in XML tags |
| prefill | string |
Assistant prefill starting the <edited_target> response
|
Suggestions Array
| Label | Condition Heuristic | Max Weight |
|---|---|---|
| Synonym | 1-2 words selected | 3 |
| Clarity | Complex words (12+ chars) + long sentences (20+ words) | Unbounded (sum of matches) |
| Shorten | Text length > 100 characters | 2 |
| Lengthen | Text length < 100 characters | 2 |
Usage Examples
import performEditPrompt, { suggestions } from "@/prompts/perform-edit";
// Generate edit prompt
const { system, user, prefill } = performEditPrompt(
"Make this more concise",
"This is a very long and unnecessarily verbose explanation",
"The introduction states: ",
" which concludes the section."
);
// Get relevant suggestions for selected text
const selectedText = "comprehensive";
const ranked = suggestions
.map((s) => ({ ...s, weight: s.condition(selectedText) }))
.filter((s) => s.weight > 0)
.sort((a, b) => b.weight - a.weight);
// Result: [{ label: "Synonym", weight: 3, ... }]