Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langfuse Langfuse Seed Postgres

From Leeroopedia
Knowledge Sources
Domains Database Seeding, Development Infrastructure, PostgreSQL
Last Updated 2026-02-14 00:00 GMT

Overview

The main PostgreSQL seeding script that creates demo users, organizations, projects, API keys, prompts, datasets, evaluators, dashboards, and other seed data for local Langfuse development.

Description

This TypeScript script is the primary entry point for seeding the PostgreSQL database with development data. It uses Prisma Client for all database operations and supports two modes:

Base Mode (always runs):

  • Creates two demo users: demo@langfuse.com (Owner) and member@langfuse.com (Member/Admin).
  • Creates a seed organization ("Seed Org") with a "Team" cloud plan.
  • Creates the primary project "llm-app" with the well-known ID 7a88fb47-b4e2-43b8-a06c-a5ce950dc53a.
  • Creates a realistic support chat session.
  • Sets up organization and project memberships with appropriate roles.
  • Creates a "summary-prompt" prompt with production/latest labels.
  • Creates an API key (pk-lf-1234567890 / sk-lf-1234567890) for the project.

Extended Mode (when --environment=examples or --environment=load):

  • Creates a second organization ("Langfuse Demo") with a second project ("demo-app") and API key.
  • Generates score configurations (Numeric, Categorical "Accuracy", Boolean "Toxicity").
  • Creates annotation queues linked to score configs.
  • Generates multiple prompt types: text prompts (with variable versions), ChatML prompts (with placeholders), and a comprehensive filter-condition chat prompt.
  • Creates multiple datasets with items: countries (51 items), IPA transcriptions (100 items), math operations, colors, simple names, greetings, and a versioning test dataset with 4 versions.
  • Creates dataset runs (3 per dataset that supports experiments).
  • Creates dataset item versions with temporal validity ranges.
  • Seeds evaluator templates and job configurations (toxicity evaluation).
  • Generates eval job executions (100 per project, with 10% error rate).
  • Creates trace sessions (100 per project).
  • Creates dashboards with widgets (trace counts, observation latencies).
  • Seeds dataset versions via seedDatasetVersions.
  • Seeds media test traces via seedMediaTraces.
  • Creates LLM schemas (get_weather, calculator).
  • Optionally creates an LLM API key from the OPENAI_API_KEY environment variable.

The script accepts a --environment CLI argument and disconnects from both PostgreSQL and Redis upon completion.

Usage

Use this script when:

  • Setting up a fresh local development environment with realistic demo data.
  • Resetting the PostgreSQL database to a known seed state.
  • Running pnpm run db:seed or as part of pnpm run dx.
  • Testing features that depend on specific seed data (datasets, prompts, evaluators).

Code Reference

Source Location

Signature

// Main entry point
async function main(): Promise<void>

// Exported functions
export async function createDatasets(
  project1: { id: string; orgId: string; createdAt: Date; updatedAt: Date; name: string },
  project2: { id: string; orgId: string; createdAt: Date; updatedAt: Date; name: string },
): Promise<void>

export const PROMPT_IDS: string[]

// Internal functions
async function generateEvalJobExecutions(projects: Project[], evalJobConfigurations: Partial<JobConfiguration>[]): Promise<void>
async function generatePromptsForProject(projects: Project[]): Promise<Map<string, string[]>>
async function generatePrompts(project: Project): Promise<string[]>
async function generateConfigsForProject(projects: Project[]): Promise<Map<string, {...}[]>>
async function generateConfigs(project: Project): Promise<{...}[]>
async function generateQueuesForProject(projects: Project[], configIdsAndNames: Map<...>): Promise<Map<string, string[]>>
async function generateQueues(project: Project, configIdsAndNames: {...}[]): Promise<string[]>
async function createTraceSessions(project1: Project, project2: Project): Promise<void>
async function createSupportChatSession(project: Project): Promise<void>
async function createDashboardsAndWidgets(projects: Project[]): Promise<void>

Import

import { PrismaClient } from "../../src/index";
import { SEED_DATASETS, SEED_TEXT_PROMPTS, SEED_CHAT_ML_PROMPTS, SEED_PROMPT_VERSIONS, SEED_EVALUATOR_TEMPLATES, SEED_EVALUATOR_CONFIGS, EVAL_TRACE_COUNT, FAILED_EVAL_TRACE_INTERVAL } from "./utils/postgres-seed-constants";

I/O Contract

Inputs

Name Type Required Description
--environment CLI argument (string) No Set to "examples" or "load" to enable extended seeding with datasets, prompts, evaluators, and a second org/project
SEED_SECRET_KEY Environment variable No Custom secret key for the seeded API key (defaults to sk-lf-1234567890)
OPENAI_API_KEY Environment variable No If set, creates an OpenAI LLM API key in the project for evaluation features

Outputs

Name Type Description
Users PostgreSQL rows Two demo users with hashed passwords
Organizations PostgreSQL rows 1-2 organizations with cloud config
Projects PostgreSQL rows 1-2 projects with API keys
Prompts PostgreSQL rows Multiple text and ChatML prompts with versions and labels
Datasets PostgreSQL rows 7 datasets with items, runs, and versioned items
Evaluators PostgreSQL rows Eval templates, job configurations, and job executions
Dashboards PostgreSQL rows Dashboard with two widgets (trace counts, observation latencies)
Score Configs PostgreSQL rows Numeric, Categorical, and Boolean score configurations

Usage Examples

// Run from packages/shared/:
// pnpm run db:seed

// Run with extended data:
// pnpm run db:seed -- --environment=examples

// Programmatic usage (e.g., from tests):
import { createDatasets } from "./seed-postgres";

const project1 = { id: "proj-1", orgId: "org-1", name: "test", createdAt: new Date(), updatedAt: new Date() };
const project2 = { id: "proj-2", orgId: "org-1", name: "test2", createdAt: new Date(), updatedAt: new Date() };
await createDatasets(project1, project2);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment