loom

Production-ready Go library for managing, testing, optimizing, and versioning prompts for Large Language Models (LLMs). Type-safe, performant, provider-agnostic.

Install

go get github.com/klejdi94/loom

How it works

End-to-end flow: define versioned prompts → store in Postgres or Redis → promote → run via provider → record to analytics (Postgres/Redis) → view on dashboard.

flowchart LR subgraph Define A[Prompt + Version] --> B[Store] end subgraph Registry B --> C[(Postgres)] B --> D[(Redis)] C --> E[Promote] D --> E E --> F[GetProduction] end subgraph Run F --> G[Execute] G --> H[Provider] H --> I[LLM] I --> J[Record] end subgraph Analytics J --> K[(Postgres)] J --> L[(Redis)] K --> M[Dashboard] L --> M end
StepWhat happens
DefineBuild prompt (ID, version, system, template, variables).
StoreRegistry: Postgres, Redis, file, or memory.
PromoteMark a version as production.
ExecuteLoad production prompt, call provider (OpenAI, Cerebras, etc.).
RecordAnalytics: persist run (prompt_id, version, latency, success) in Postgres or Redis.
DashboardCharts: runs over time, success rate by prompt/version.

Quick start

engine := loom.DefaultEngine()
prompt := loom.New("my-prompt").
    WithSystem("You are a helpful assistant.").
    WithTemplate("Answer: {{.question}}").
    WithVariable("question", loom.String(loom.Required())).
    Build(engine)

result, _ := prompt.Render(ctx, loom.Input{"question": "What is 2+2?"})

Registry: Postgres and Redis

// PostgreSQL
db, _ := sql.Open("postgres", dsn)
reg, _ := registry.NewPostgresRegistry(db, "prompts", true)

// Redis
rdb := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
reg := registry.NewRedisRegistry(rdb, "loom:prompts")

reg.Store(ctx, prompt)
reg.Promote(ctx, "my-prompt", "1.2.0", registry.StageProduction)
prod, _ := reg.GetProduction(ctx, "my-prompt")

Analytics: Postgres and Redis

// Persistent run history (survives restarts)
// Postgres
store, _ := analytics.NewPostgresStore(db, "prompt_runs")

// Redis
store := analytics.NewRedisStore(rdb, "loom:analytics:runs")

// Server: go run ./cmd/analytics-server -store=postgres -dsn=...
// Dashboard: go run ./cmd/dashboard -api=http://localhost:8080

Features

View on GitHub   Full README & examples   Flow design