Skip to main content
ze.prompt creates or fetches versioned prompts from the Prompt Library and returns decorated content for downstream LLM calls.
TypeScript differences: In TypeScript, ze.prompt() is an async function that returns Promise<string>. Parameters use camelCase and are passed as an options object: ze.prompt({ name: "...", content: "..." }).

Parameters

PythonTypeScriptTypeRequiredDefaultDescription
namenamestringyesTask name associated with the prompt in the library
contentcontentstringnoNone/undefinedRaw prompt content to ensure/create a version by content
from_fromstringnoNone/undefinedEither "latest", "explicit", or a 64‑char SHA‑256 hash
variablesvariablesdict/objectnoNone/undefinedTemplate variables to render {{variable}} tokens
Notes:
  • In Python, use from_ (with underscore) as from is a reserved keyword. TypeScript uses from directly.
  • Exactly one of content or from must be provided (except when using from: "explicit" with content).
  • from="latest" fetches the latest version bound to the task; otherwise from must be a 64‑char hex SHA‑256 hash.

Behavior

  • content provided: Computes a normalized SHA‑256 hash, ensures a prompt version exists for name, and returns decorated content.
  • from=“latest”: Fetches the latest version for name and returns decorated content.
  • from=<hash>: Fetches by content hash for name and returns decorated content.
Decoration adds a compact metadata header used by integrations:
  • task, prompt_slug, prompt_version, prompt_version_id, variables, and (when created by content) content_hash.
OpenAI integration: when prompt_version_id is present, the SDK will automatically patch the model parameter to the model bound to that prompt version.

Return Value

  • Python: str - Decorated prompt content ready to pass into LLM clients.
  • TypeScript: Promise<string> - Async function returning decorated prompt content.

Errors

PythonTypeScriptWhen
ValueErrorErrorBoth content and from provided (except explicit), or neither; invalid from value
PromptRequestErrorPromptRequestErrorfrom="latest" but no versions exist for name
PromptNotFoundErrorPromptNotFoundErrorfrom is a hash that does not exist for name

Examples

import zeroeval as ze

# Create/ensure a version by content
system = ze.prompt(
    name="support-triage",
    content="You are a helpful assistant for {{product}}.",
    variables={"product": "Acme"},
)

# Fetch the latest version for this task
system = ze.prompt(name="support-triage", from_="latest")

# Fetch a specific version by content hash
system = ze.prompt(name="support-triage", from_="c6a7...deadbeef...0123")