or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

advanced.mdannotation-queues.mdanonymizer.mdclient-api.mddatasets.mdevaluation.mdfeedback.mdgetting-started.mdindex.mdjest.mdlangchain.mdopentelemetry.mdprompts.mdrun-trees.mdschemas.mdtesting.mdtracing.mdvercel.mdvitest.mdworkflows.mdwrappers.md
tile.json

prompts.mddocs/

Prompt Management

Comprehensive prompt management functionality for storing, versioning, and sharing prompts through the LangSmith Prompt Hub. The prompt hub enables teams to collaborate on prompts, track versions, and manage prompt lifecycles across development and production environments.

Capabilities

Create Prompt

Creates a new prompt in the LangSmith prompt hub with version control and metadata support.

/**
 * Creates a new prompt in the LangSmith prompt hub
 * @param promptIdentifier - Prompt identifier in format "owner/prompt-name" or just "prompt-name"
 * @param options - Optional prompt configuration
 * @returns Promise resolving to created Prompt object
 */
createPrompt(
  promptIdentifier: string,
  options?: {
    description?: string;
    readme?: string;
    tags?: string[];
    isPublic?: boolean;
  }
): Promise<Prompt>;

Usage Examples:

import { Client } from "langsmith";

const client = new Client();

// Create a simple text prompt
const prompt = await client.createPrompt("customer-greeting", {
  description: "Standard customer greeting template",
  tags: ["customer-service", "greeting"],
  isPublic: false,
});

// Create a prompt with owner/name format
const orgPrompt = await client.createPrompt("myorg/ai-assistant", {
  description: "Base AI assistant prompt",
  tags: ["assistant", "chat"],
  isPublic: true,
});

// Create a prompt with readme documentation
const analyticsPrompt = await client.createPrompt("data-analysis", {
  description: "Data analysis prompt with customizable focus",
  readme: "Use this prompt for analyzing datasets with specific focus areas.",
  tags: ["analytics", "data-science"],
  isPublic: false,
});

Delete Prompt

Deletes a prompt from the LangSmith prompt hub.

/**
 * Deletes a prompt from the LangSmith prompt hub
 * @param promptIdentifier - Prompt identifier in format "owner/prompt-name" or just "prompt-name"
 * @returns Promise resolving when deletion is complete
 */
deletePrompt(promptIdentifier: string): Promise<void>;

Usage Examples:

import { Client } from "langsmith";

const client = new Client();

// Delete a prompt
await client.deletePrompt("customer-greeting");

// Delete prompt with owner prefix
await client.deletePrompt("myorg/ai-assistant");

// Delete with error handling
try {
  await client.deletePrompt("old-prompt");
  console.log("Prompt deleted successfully");
} catch (error) {
  console.error("Failed to delete prompt:", error.message);
}

Pull Prompt

Retrieves a prompt from the LangSmith prompt hub, optionally specifying a specific version or commit.

/**
 * Pulls a prompt from the LangSmith prompt hub
 * @param params - Pull parameters
 * @returns Promise resolving to Prompt object with commit information
 */
pullPrompt(params: PullPromptParams): Promise<Prompt>;

interface PullPromptParams {
  /** Name of the prompt to pull */
  promptName: string;
  /** Optional: specific commit hash or version tag */
  commit?: string;
  /** Optional: include full commit history */
  includeHistory?: boolean;
}

Usage Examples:

import { Client } from "langsmith";

const client = new Client();

// Pull latest version of a prompt
const prompt = await client.pullPrompt({
  promptName: "customer-greeting",
});
console.log("Latest prompt:", prompt.content);

// Pull specific version by commit hash
const specificPrompt = await client.pullPrompt({
  promptName: "ai-assistant",
  commit: "a1b2c3d4e5f6",
});

// Pull prompt with full history
const promptWithHistory = await client.pullPrompt({
  promptName: "data-analysis",
  includeHistory: true,
});
console.log("Commit history:", promptWithHistory.commits);

// Use prompt in your application
const greetingPrompt = await client.pullPrompt({
  promptName: "customer-greeting",
});
const message = greetingPrompt.content.replace("{name}", "Alice");
console.log(message); // "Hello Alice, welcome to our service!"

// Pull and format a chat prompt
const chatPrompt = await client.pullPrompt({
  promptName: "ai-assistant",
});
const messages = chatPrompt.content.messages.map((msg) => ({
  role: msg.role,
  content: msg.content.replace("{user_input}", "What is AI?"),
}));

Push Prompt

Updates or creates a new version of a prompt in the LangSmith prompt hub, creating a new commit in the version history.

/**
 * Pushes a prompt to the LangSmith prompt hub, creating a new version
 * @param promptIdentifier - Prompt identifier in format "owner/prompt-name" or just "prompt-name"
 * @param options - Push options including prompt object and metadata
 * @returns Promise resolving to prompt URL
 */
pushPrompt(
  promptIdentifier: string,
  options?: {
    object?: any;
    parentCommitHash?: string;
    isPublic?: boolean;
    description?: string;
    readme?: string;
    tags?: string[];
  }
): Promise<string>;

Usage Examples:

import { Client } from "langsmith";

const client = new Client();

// Push a prompt object (creates new commit)
const promptUrl = await client.pushPrompt("customer-greeting", {
  object: {
    type: "chat",
    messages: [
      { role: "system", content: "You are a helpful customer service agent." },
      { role: "user", content: "{customer_query}" },
    ],
  },
  description: "Customer service greeting prompt",
  tags: ["customer-service", "v2"],
});

console.log("Prompt URL:", promptUrl);

// Push with parent commit for version tracking
const currentCommit = await client.pullPromptCommit("ai-assistant");
await client.pushPrompt("ai-assistant", {
  object: {
    type: "chat",
    messages: [
      { role: "system", content: "You are a helpful and friendly AI assistant." },
      { role: "user", content: "{user_input}" },
    ],
  },
  parentCommitHash: currentCommit.manifest_id,
  description: "Made assistant more friendly",
});

// Update metadata only (no new commit)
await client.pushPrompt("data-analysis", {
  description: "Updated description",
  tags: ["analytics", "data-science", "production"],
  isPublic: true,
});

Check Prompt Existence

Check if a prompt exists in the prompt hub before attempting to pull or update it.

/**
 * Check if a prompt exists
 * @param promptIdentifier - Prompt name or full identifier
 * @returns Promise resolving to boolean indicating existence
 */
promptExists(promptIdentifier: string): Promise<boolean>;

Usage Examples:

import { Client } from "langsmith";

const client = new Client();

// Check if prompt exists before pulling
const exists = await client.promptExists("customer-greeting");
if (exists) {
  const prompt = await client.pullPrompt({ promptName: "customer-greeting" });
  console.log("Using existing prompt");
} else {
  console.log("Prompt not found, creating new one");
  await client.createPrompt({
    promptName: "customer-greeting",
    content: "Hello {name}!",
  });
}

// Check with full identifier (owner/prompt format)
const orgPromptExists = await client.promptExists("myorg/production-prompt");

List Commits

List all commits (versions) for a specific prompt, showing the complete version history.

/**
 * List commits for a prompt
 * @param params - List commits parameters
 * @returns Async iterable of prompt commits
 */
listCommits(params: {
  promptName: string;
  limit?: number;
  offset?: number;
}): AsyncIterable<PromptCommit>;

Usage Examples:

import { Client } from "langsmith";

const client = new Client();

// List all commits for a prompt
for await (const commit of client.listCommits({
  promptName: "ai-assistant",
})) {
  console.log(`Commit: ${commit.commit_hash}`);
  console.log(`Message: ${commit.commit_message}`);
  console.log(`Date: ${commit.created_at}`);
  console.log(`Author: ${commit.author}`);
  console.log("---");
}

// List recent commits with limit
for await (const commit of client.listCommits({
  promptName: "customer-greeting",
  limit: 10,
})) {
  console.log(`${commit.created_at}: ${commit.commit_message}`);
}

Create Commit

Create a new commit for a prompt, similar to pushPrompt but with more explicit version control semantics.

/**
 * Create a new commit for a prompt
 * @param params - Commit creation parameters
 * @returns Promise resolving to created commit
 */
createCommit(params: {
  promptName: string;
  content: string | object;
  commitMessage: string;
  parentCommit?: string;
  metadata?: KVMap;
}): Promise<PromptCommit>;

Usage Examples:

import { Client } from "langsmith";

const client = new Client();

// Create a new commit with explicit message
const commit = await client.createCommit({
  promptName: "ai-assistant",
  content: {
    messages: [
      { role: "system", content: "You are a helpful AI assistant with expertise in coding." },
      { role: "user", content: "{user_input}" },
    ],
  },
  commitMessage: "Added coding expertise to system message",
  metadata: { author: "dev-team", reviewed: true },
});

console.log(`Created commit: ${commit.commit_hash}`);

Pull Prompt Commit

Pull a specific commit of a prompt by commit hash, useful for retrieving exact historical versions.

/**
 * Pull a specific commit of a prompt
 * @param promptIdentifier - Prompt identifier in format "owner/prompt-name" or just "prompt-name"
 * @param options - Optional pull options
 * @returns Promise resolving to prompt commit
 */
pullPromptCommit(
  promptIdentifier: string,
  options?: {
    includeModel?: boolean;
    skipCache?: boolean;
  }
): Promise<PromptCommit>;

Usage Examples:

import { Client } from "langsmith";

const client = new Client();

// Pull latest commit
const commit = await client.pullPromptCommit("ai-assistant");
console.log("Latest commit:", commit.manifest);

// Pull with model included (for formatted output)
const commitWithModel = await client.pullPromptCommit("ai-assistant", {
  includeModel: true,
});

// Skip cache to get fresh data
const freshCommit = await client.pullPromptCommit("customer-greeting", {
  skipCache: true,
});

console.log("Commit manifest:", freshCommit.manifest);
console.log("Commit ID:", freshCommit.manifest_id);

Like Prompt

Adds a like/star to a prompt in the prompt hub, useful for indicating community favorites or team-approved prompts.

/**
 * Likes a prompt in the LangSmith prompt hub
 * @param params - Like parameters
 * @returns Promise resolving to LikePromptResponse
 */
likePrompt(params: LikePromptParams): Promise<LikePromptResponse>;

interface LikePromptParams {
  /** Name of the prompt to like */
  promptName: string;
  /** Optional: specific commit hash to like */
  commitHash?: string;
}

interface LikePromptResponse {
  /** Whether the like was successful */
  success: boolean;
  /** Updated like count */
  likeCount: number;
}

Usage Examples:

import { Client } from "langsmith";

const client = new Client();

// Like the latest version of a prompt
const likeResult = await client.likePrompt({
  promptName: "customer-greeting",
});
console.log(`Prompt now has ${likeResult.likeCount} likes`);

// Like a specific version
await client.likePrompt({
  promptName: "ai-assistant",
  commitHash: "a1b2c3d4e5f6",
});

// Like and track popularity
const response = await client.likePrompt({
  promptName: "data-analysis",
});
if (response.success) {
  console.log("Thank you for liking this prompt!");
}

Unlike Prompt

Removes a like/star from a prompt in the prompt hub.

/**
 * Unlikes a prompt in the LangSmith prompt hub
 * @param params - Unlike parameters
 * @returns Promise resolving when unlike is complete
 */
unlikePrompt(params: UnlikePromptParams): Promise<void>;

interface UnlikePromptParams {
  /** Name of the prompt to unlike */
  promptName: string;
  /** Optional: specific commit hash to unlike */
  commitHash?: string;
}

Usage Examples:

import { Client } from "langsmith";

const client = new Client();

// Unlike the latest version of a prompt
await client.unlikePrompt({
  promptName: "customer-greeting",
});

// Unlike a specific version
await client.unlikePrompt({
  promptName: "ai-assistant",
  commitHash: "a1b2c3d4e5f6",
});

// Unlike with confirmation
try {
  await client.unlikePrompt({
    promptName: "data-analysis",
  });
  console.log("Like removed");
} catch (error) {
  console.error("Failed to unlike:", error.message);
}

List Prompts

Lists prompts from the LangSmith prompt hub with filtering and sorting support.

/**
 * Lists prompts from the LangSmith prompt hub
 * @param options - List options with filtering
 * @returns Async iterable of prompts
 */
listPrompts(options?: {
  isPublic?: boolean;
  isArchived?: boolean;
  sortField?: PromptSortField;
  query?: string;
}): AsyncIterableIterator<Prompt>;

type PromptSortField =
  | "created_at"
  | "updated_at"
  | "name"
  | "like_count"
  | "num_commits";

Usage Examples:

import { Client } from "langsmith";

const client = new Client();

// List all prompts (async iterable)
for await (const prompt of client.listPrompts()) {
  console.log(`- ${prompt.repo_handle}: ${prompt.description}`);
}

// Search for prompts by name
for await (const prompt of client.listPrompts({ query: "customer" })) {
  console.log(`Found: ${prompt.repo_handle}`);
}

// List public prompts only
for await (const prompt of client.listPrompts({ isPublic: true })) {
  console.log(`Public prompt: ${prompt.repo_handle}`);
}

// List prompts sorted by popularity
for await (const prompt of client.listPrompts({
  sortField: "like_count",
})) {
  console.log(`${prompt.repo_handle} - ${prompt.num_likes} likes`);
}

// List recently updated prompts
for await (const prompt of client.listPrompts({
  sortField: "updated_at",
})) {
  console.log(`${prompt.repo_handle} updated ${prompt.updated_at}`);
}

// Collect prompts into array
const prompts: Prompt[] = [];
for await (const prompt of client.listPrompts({ isPublic: true })) {
  prompts.push(prompt);
  if (prompts.length >= 10) break; // Limit to 10
}
console.log(`Collected ${prompts.length} prompts`);

Get Prompt URL

Gets the URL for viewing a prompt in the LangSmith web interface.

/**
 * Gets the URL for viewing a prompt in the LangSmith UI
 * @param params - URL parameters
 * @returns Promise resolving to the prompt's web URL
 */
getPromptUrl(params: GetPromptUrlParams): Promise<string>;

interface GetPromptUrlParams {
  /** Name of the prompt */
  promptName: string;
  /** Optional: specific commit hash for version URL */
  commitHash?: string;
}

Usage Examples:

import { Client } from "langsmith";

const client = new Client();

// Get URL for latest prompt version
const promptUrl = await client.getPromptUrl({
  promptName: "customer-greeting",
});
console.log(`View prompt: ${promptUrl}`);

// Get URL for specific version
const versionUrl = await client.getPromptUrl({
  promptName: "ai-assistant",
  commitHash: "a1b2c3d4e5f6",
});

// Share prompt URL with team
const url = await client.getPromptUrl({
  promptName: "data-analysis",
});
console.log(`Share this prompt: ${url}`);

// Create clickable link in logs
const promptName = "customer-greeting";
const url = await client.getPromptUrl({ promptName });
console.log(`Prompt details: <${url}>`);

Update Prompt

Updates prompt metadata such as description, tags, or visibility without creating a new version.

/**
 * Updates prompt metadata (description, tags, visibility)
 * @param params - Update parameters
 * @returns Promise resolving to updated Prompt
 */
updatePrompt(params: UpdatePromptParams): Promise<Prompt>;

interface UpdatePromptParams {
  /** Name of the prompt to update */
  promptName: string;
  /** Optional: new description */
  description?: string;
  /** Optional: new tags (replaces existing tags) */
  tags?: string[];
  /** Optional: updated metadata (merges with existing) */
  metadata?: KVMap;
  /** Optional: change visibility */
  isPublic?: boolean;
}

Usage Examples:

import { Client } from "langsmith";

const client = new Client();

// Update description
await client.updatePrompt({
  promptName: "customer-greeting",
  description: "Updated greeting template for all customer interactions",
});

// Change visibility to public
await client.updatePrompt({
  promptName: "ai-assistant",
  isPublic: true,
});

// Update tags
await client.updatePrompt({
  promptName: "data-analysis",
  tags: ["analytics", "data-science", "production", "v2"],
});

// Update metadata only
await client.updatePrompt({
  promptName: "customer-greeting",
  metadata: {
    last_reviewed: new Date().toISOString(),
    reviewer: "team-lead",
    status: "approved",
  },
});

// Comprehensive update
const updated = await client.updatePrompt({
  promptName: "ai-assistant",
  description: "Production-ready AI assistant prompt",
  tags: ["production", "assistant", "approved"],
  isPublic: true,
  metadata: {
    version: "2.1",
    approved_by: "ai-team",
    deployment_date: "2024-01-15",
  },
});
console.log("Updated prompt:", updated);

Schemas and Types

Prompt Schema

The main prompt object returned by prompt operations.

interface Prompt {
  /** Unique identifier for the prompt */
  id: string;
  /** Prompt name (identifier in hub) */
  name: string;
  /** Prompt description */
  description?: string;
  /** Prompt content/template (string or structured object) */
  content: string | object;
  /** Tags associated with the prompt */
  tags: string[];
  /** Metadata key-value pairs */
  metadata: KVMap;
  /** Whether prompt is public */
  isPublic: boolean;
  /** Creator user ID */
  createdBy: string;
  /** Creation timestamp */
  createdAt: string;
  /** Last update timestamp */
  updatedAt: string;
  /** Latest commit hash */
  commitHash: string;
  /** Number of versions/commits */
  numCommits: number;
  /** Number of likes */
  likeCount: number;
  /** Whether current user has liked this prompt */
  isLiked: boolean;
  /** Commit history (when includeHistory is true) */
  commits?: PromptCommit[];
}

PromptCommit Schema

Represents a single version/commit in a prompt's history.

interface PromptCommit {
  /** Unique commit hash */
  hash: string;
  /** Commit message describing changes */
  message?: string;
  /** Parent commit hash */
  parentHash?: string;
  /** Prompt content at this commit */
  content: string | object;
  /** Tags at this commit */
  tags: string[];
  /** Metadata at this commit */
  metadata: KVMap;
  /** Commit author user ID */
  authorId: string;
  /** Commit timestamp */
  createdAt: string;
}

CreatePromptParams Schema

Parameters for creating a new prompt.

interface CreatePromptParams {
  /** Name of the prompt (used as identifier in hub) */
  promptName: string;
  /** Prompt content/template */
  content: string | object;
  /** Optional description of the prompt */
  description?: string;
  /** Optional tags for categorization */
  tags?: string[];
  /** Optional metadata key-value pairs */
  metadata?: KVMap;
  /** Whether prompt is public (default: false) */
  isPublic?: boolean;
}

DeletePromptParams Schema

Parameters for deleting a prompt or specific version.

interface DeletePromptParams {
  /** Name of the prompt to delete */
  promptName: string;
  /** Optional: specific commit hash to delete (deletes entire prompt if not provided) */
  commitHash?: string;
}

PullPromptParams Schema

Parameters for pulling a prompt from the hub.

interface PullPromptParams {
  /** Name of the prompt to pull */
  promptName: string;
  /** Optional: specific commit hash or version tag */
  commit?: string;
  /** Optional: include full commit history */
  includeHistory?: boolean;
}

PushPromptParams Schema

Parameters for pushing an updated prompt version.

interface PushPromptParams {
  /** Name of the prompt */
  promptName: string;
  /** Updated prompt content/template */
  content: string | object;
  /** Optional: description of changes in this version */
  commitMessage?: string;
  /** Optional: parent commit hash (for version tracking) */
  parentCommit?: string;
  /** Optional: tags for this version */
  tags?: string[];
  /** Optional: metadata for this version */
  metadata?: KVMap;
  /** Whether prompt is public */
  isPublic?: boolean;
}

LikePromptParams Schema

Parameters for liking a prompt.

interface LikePromptParams {
  /** Name of the prompt to like */
  promptName: string;
  /** Optional: specific commit hash to like */
  commitHash?: string;
}

UnlikePromptParams Schema

Parameters for unliking a prompt.

interface UnlikePromptParams {
  /** Name of the prompt to unlike */
  promptName: string;
  /** Optional: specific commit hash to unlike */
  commitHash?: string;
}

ListPromptsParams Schema

Parameters for listing and filtering prompts.

interface ListPromptsParams {
  /** Filter by prompt name (supports partial match) */
  query?: string;
  /** Filter by tags (prompts must have all specified tags) */
  tags?: string[];
  /** Include only public prompts */
  isPublic?: boolean;
  /** Include only prompts created by current user */
  isOwner?: boolean;
  /** Sort field */
  sortField?: PromptSortField;
  /** Sort direction: "asc" or "desc" */
  sortDirection?: "asc" | "desc";
  /** Page number (0-indexed) */
  page?: number;
  /** Number of results per page */
  limit?: number;
}

type PromptSortField = "created_at" | "updated_at" | "name" | "like_count" | "num_commits";

GetPromptUrlParams Schema

Parameters for getting a prompt's web URL.

interface GetPromptUrlParams {
  /** Name of the prompt */
  promptName: string;
  /** Optional: specific commit hash for version URL */
  commitHash?: string;
}

UpdatePromptParams Schema

Parameters for updating prompt metadata.

interface UpdatePromptParams {
  /** Name of the prompt to update */
  promptName: string;
  /** Optional: new description */
  description?: string;
  /** Optional: new tags (replaces existing tags) */
  tags?: string[];
  /** Optional: updated metadata (merges with existing) */
  metadata?: KVMap;
  /** Optional: change visibility */
  isPublic?: boolean;
}

ListPromptsResponse Schema

Response object from listing prompts.

interface ListPromptsResponse {
  /** Array of prompts matching the query */
  prompts: Prompt[];
  /** Total count of matching prompts */
  total: number;
  /** Current page number */
  page: number;
  /** Number of results per page */
  limit: number;
}

ListCommitsResponse Schema

Response object for listing prompt commits/versions.

interface ListCommitsResponse {
  /** Array of commits for the prompt */
  commits: PromptCommit[];
  /** Total number of commits */
  total: number;
}

LikePromptResponse Schema

Response object from liking a prompt.

interface LikePromptResponse {
  /** Whether the like was successful */
  success: boolean;
  /** Updated like count */
  likeCount: number;
}

Common Patterns and Workflows

Versioning Workflow

Track prompt changes over time with version control.

import { Client } from "langsmith";

const client = new Client();

// Create initial version
const v1 = await client.createPrompt({
  promptName: "product-description",
  content: "Write a description for: {product_name}",
  tags: ["content", "v1"],
});

// Update to v2 with tracking
const currentVersion = await client.pullPrompt({
  promptName: "product-description",
});

const v2 = await client.pushPrompt({
  promptName: "product-description",
  content: "Write a compelling description for: {product_name}\nHighlight: {key_features}",
  commitMessage: "Added key features support",
  parentCommit: currentVersion.commitHash,
  tags: ["content", "v2"],
});

// View version history
const promptWithHistory = await client.pullPrompt({
  promptName: "product-description",
  includeHistory: true,
});

console.log("Version history:");
promptWithHistory.commits?.forEach((commit) => {
  console.log(`- ${commit.hash}: ${commit.message}`);
});

// Rollback to previous version
const oldVersion = promptWithHistory.commits?.[1];
if (oldVersion) {
  await client.pushPrompt({
    promptName: "product-description",
    content: oldVersion.content,
    commitMessage: "Rolled back to previous version",
    parentCommit: currentVersion.commitHash,
  });
}

Team Collaboration Workflow

Share prompts and collaborate across teams.

import { Client } from "langsmith";

const client = new Client();

// Developer creates and shares prompt
const sharedPrompt = await client.createPrompt({
  promptName: "team-prompt",
  content: "Analyze: {input}",
  description: "Shared team analysis prompt",
  tags: ["team", "shared"],
  isPublic: true,
});

// Get shareable URL
const url = await client.getPromptUrl({
  promptName: "team-prompt",
});
console.log(`Share with team: ${url}`);

// Team member likes the prompt
await client.likePrompt({
  promptName: "team-prompt",
});

// Another team member improves it
const current = await client.pullPrompt({
  promptName: "team-prompt",
});

await client.pushPrompt({
  promptName: "team-prompt",
  content: "Analyze: {input}\nProvide actionable insights.",
  commitMessage: "Added actionable insights requirement",
  parentCommit: current.commitHash,
});

// List team's most popular prompts
const popular = await client.listPrompts({
  sortField: "like_count",
  sortDirection: "desc",
  limit: 10,
});

Production Deployment Workflow

Manage prompts across development and production environments.

import { Client } from "langsmith";

const devClient = new Client({ apiKey: process.env.DEV_API_KEY });
const prodClient = new Client({ apiKey: process.env.PROD_API_KEY });

// Develop and test in dev environment
await devClient.createPrompt({
  promptName: "customer-support",
  content: "Help with: {issue}",
  tags: ["dev", "support"],
});

// Test and iterate
const devPrompt = await devClient.pullPrompt({
  promptName: "customer-support",
});

await devClient.pushPrompt({
  promptName: "customer-support",
  content: "Help customer with: {issue}\nBe friendly and helpful.",
  commitMessage: "Improved tone",
});

// Promote to production
const approvedPrompt = await devClient.pullPrompt({
  promptName: "customer-support",
});

await prodClient.createPrompt({
  promptName: "customer-support",
  content: approvedPrompt.content,
  description: "Production customer support prompt",
  tags: ["production", "support", "approved"],
  metadata: {
    promoted_from: "dev",
    approved_by: "team-lead",
    deployed_at: new Date().toISOString(),
  },
  isPublic: false,
});

// Mark as production-ready
await prodClient.updatePrompt({
  promptName: "customer-support",
  metadata: {
    status: "active",
    version: "1.0",
  },
});

Prompt Template Management

Manage and organize prompt templates for different use cases.

import { Client } from "langsmith";

const client = new Client();

// Create category of prompts
const categories = [
  {
    name: "email-confirmation",
    content: "Subject: {subject}\n\nDear {customer_name},\n\n{body}",
    tags: ["email", "confirmation"],
  },
  {
    name: "email-reminder",
    content: "Subject: Reminder - {subject}\n\nHi {customer_name},\n\n{reminder_text}",
    tags: ["email", "reminder"],
  },
  {
    name: "email-support",
    content: "Subject: Re: {ticket_id}\n\nDear {customer_name},\n\n{response}",
    tags: ["email", "support"],
  },
];

// Bulk create prompts
for (const prompt of categories) {
  await client.createPrompt({
    promptName: prompt.name,
    content: prompt.content,
    tags: prompt.tags,
    description: `Template for ${prompt.tags.join(" ")} emails`,
  });
}

// Find all email templates
const emailTemplates = await client.listPrompts({
  tags: ["email"],
});

console.log(`Found ${emailTemplates.total} email templates`);

// Use template
const confirmationTemplate = await client.pullPrompt({
  promptName: "email-confirmation",
});

const email = (confirmationTemplate.content as string)
  .replace("{subject}", "Order Confirmation")
  .replace("{customer_name}", "John")
  .replace("{body}", "Your order has been confirmed.");

console.log(email);

A/B Testing Workflow

Test multiple prompt variations.

import { Client } from "langsmith";

const client = new Client();

// Create baseline prompt
await client.createPrompt({
  promptName: "product-recommendation",
  content: "Recommend products for: {user_preferences}",
  tags: ["recommendations", "baseline"],
  metadata: { variant: "A", test_id: "rec-test-001" },
});

// Create variant B
const baselinePrompt = await client.pullPrompt({
  promptName: "product-recommendation",
});

await client.pushPrompt({
  promptName: "product-recommendation",
  content: "Based on {user_preferences}, suggest products they'll love:",
  commitMessage: "Variant B: More engaging language",
  parentCommit: baselinePrompt.commitHash,
  tags: ["recommendations", "variant-b"],
  metadata: { variant: "B", test_id: "rec-test-001" },
});

// Create variant C
await client.pushPrompt({
  promptName: "product-recommendation",
  content: "Products for you: {user_preferences}\nPersonalized picks:",
  commitMessage: "Variant C: Concise format",
  tags: ["recommendations", "variant-c"],
  metadata: { variant: "C", test_id: "rec-test-001" },
});

// Track which variant is active
await client.updatePrompt({
  promptName: "product-recommendation",
  metadata: {
    active_variant: "B",
    test_status: "running",
  },
});

// After testing, mark winner
await client.updatePrompt({
  promptName: "product-recommendation",
  tags: ["recommendations", "winner"],
  metadata: {
    winning_variant: "B",
    test_status: "completed",
    test_end_date: new Date().toISOString(),
  },
});

Client | Evaluation