Back to Opik

Prompt Library Overview

apps/opik-documentation/documentation/fern/docs-v2/prompt_engineering/overview.mdx

2.0.53-6919-merge-21972.4 KB
Original Source

The Prompt Library is the central place to manage every prompt your agent depends on. Version them, iterate on new versions from the Opik UI or the SDK, and link the exact version that produced a trace.

Why use the Prompt Library

When prompts are hardcoded, every change requires a code change to update. There is no history of what changed, no way to roll back quickly, and no clean way to compare alternative versions.

The Prompt Library gives you version control for the prompts that drive your agent. Push them to Opik once, and from there you can compare versions, fetch a specific one, or always follow the latest.

Key features

  • Project-scoped prompts — Every prompt lives inside a project, so different agents can have prompts with the same name without colliding.
  • Versioning by v1, v2, v3, … — Each change creates a new immutable, sequentially numbered version. Fetch a specific one with the version selector (e.g. "v3"), or omit it to fetch the most recent.
  • Text and chat prompts — Version simple string templates as well as multi-message chat templates with {{variable}} substitution.
  • Agent configuration in one place — Prompts live alongside the rest of an agent configuration (model, parameters, tools) so a trace links back to the exact bundle that produced it.
  • Python and TypeScript SDKs — Create, fetch, and render prompts from either language.

How it works

  1. Define your prompts — Use create_prompt / create_chat_prompt to send your prompts to Opik. This becomes v1.
  2. Fetch at runtime — Call get_prompt / get_chat_prompt from inside a tracked function. The SDK returns the requested version and links it to the trace automatically.
  3. Iterate from the UI — Edit the prompt and save a new version. If your code doesn't pin a version, the agent picks up the new version on its next fetch — otherwise update your code to point at the new version name.

Next steps