Langfuse JS/TS SDKs
    Preparing search index...

    Class TextPromptClient

    Client for working with text-based prompts.

    Provides methods to compile text prompts with variable substitution and convert them to LangChain-compatible formats.

    Hierarchy

    • BasePromptClient
      • TextPromptClient
    Index

    Constructors

    • Creates a new TextPromptClient instance.

      Parameters

      • prompt: Text

        The text prompt data

      • isFallback: boolean = false

        Whether this is fallback content

      Returns TextPromptClient

    Properties

    commitMessage: undefined | null | string

    Optional commit message for the prompt version

    config: unknown

    Configuration object associated with the prompt

    isFallback: boolean

    Whether this prompt client is using fallback content

    labels: string[]

    Labels associated with the prompt

    name: string

    The name of the prompt

    prompt: string

    The text content of the prompt

    promptResponse: Text

    The original prompt response from the API

    tags: string[]

    Tags associated with the prompt

    type: "chat" | "text"

    The type of prompt ("text" or "chat")

    version: number

    The version number of the prompt

    Methods

    • Parameters

      • content: string

      Returns string

    • Compiles the text prompt by substituting variables.

      Uses Mustache templating to replace {{variable}} placeholders with provided values.

      Parameters

      • Optionalvariables: Record<string, string>

        Key-value pairs for variable substitution

      • Optional_placeholders: Record<string, any>

        Ignored for text prompts

      Returns string

      The compiled text with variables substituted

      const prompt = await langfuse.prompt.get("greeting", { type: "text" });
      const compiled = prompt.compile({ name: "Alice" });
      // If prompt is "Hello {{name}}!", result is "Hello Alice!"
    • Escapes every curly brace that is part of a JSON object by doubling it.

      A curly brace is considered “JSON-related” when, after skipping any immediate whitespace, the next non-whitespace character is a single (') or double (") quote.

      Braces that are already doubled (e.g. {{variable}} placeholders) are left untouched.

      Parameters

      • text: string

        Input string that may contain JSON snippets.

      Returns string

      The string with JSON-related braces doubled.

    • Converts the prompt to LangChain PromptTemplate format.

      Transforms Mustache-style {{variable}} syntax to LangChain's {variable} format.

      Parameters

      • Optional_options: { placeholders?: Record<string, any> }

        Ignored for text prompts

      Returns string

      The prompt string compatible with LangChain PromptTemplate

      const prompt = await langfuse.prompt.get("greeting", { type: "text" });
      const langchainFormat = prompt.getLangchainPrompt();
      // Transforms "Hello {{name}}!" to "Hello {name}!"
    • Serializes the prompt client to JSON.

      Returns string

      JSON string representation of the prompt