Prompts

SDK reference

Every prompt method in trodo-node and trodo-python: get, compile, list, renderTemplate and clearCache, with their options, return shapes and errors.

The SDK fetches and compiles prompts. To create prompts, save versions or move labels, use the app, the CLI (trodo prompts push, trodo prompts label) or MCP (manage_prompt). Everything here works after init.

get

Fetch a prompt by name. See Fetch in production for how the version is chosen and how caching works.

trodo.prompts.get(name: string, options?: GetPromptOptions): Promise<ManagedPrompt>
OptionDefaultWhat it does
labelproductionFollow this label.
versionPin a version: its hash (full or a short prefix) or its number. Not with label.
cacheTtlSeconds60How long a fetch stays fresh. 0 fetches every time.
fallback{ messages, model?, variables? }, used when nothing is cached and Trodo can't be reached.
recordVariablesfalseRecord the values each compile receives on the span. See Traceability.
maxRetries2Retries on a failed fetch, at most 4.
trodo.get_prompt(
    name: str,
    label: str | None = None,
    version: int | str | None = None,
    cache_ttl_seconds: float | None = None,
    fallback: dict | None = None,
    max_retries: int = 2,
    record_variables: bool = False,
) -> ManagedPrompt
ArgumentDefaultWhat it does
labelproductionFollow this label.
versionPin a version: its hash (full or a short prefix) or its number. Not with label.
cache_ttl_seconds60How long a fetch stays fresh. 0 fetches every time.
fallback{"messages": ..., "model": ..., "variables": ...}, used when nothing is cached and Trodo can't be reached.
max_retries2Retries on a failed fetch, at most 4.
record_variablesFalseRecord the values each compile receives on the span. See Traceability.

Errors. Passing both label and version throws (Python ValueError, as does an empty name). A label or version that doesn't exist on the prompt throws at once with code set to label_not_found, version_not_found or no_versions (Python LookupError with e.code). When the prompt can't be fetched, nothing is cached and there is no fallback, get throws (Python LookupError).

compile

Fill the variables and return what to send. Runs in your process, with no network call.

prompt.compile(variables?: Record<string, unknown>): CompiledPrompt
// also: trodo.prompts.compile(prompt, variables)

interface CompiledPrompt {
  messages: PromptMessage[];       // { role, content: [{ type: 'text', text }, ...] }
  model: ModelConfig;              // as saved
  tools: PromptTool[];             // as saved
  response_format: ResponseFormat | null;
}
prompt.compile(variables: dict | None = None, **kwargs) -> CompiledPrompt
# also: trodo.compile_prompt(prompt, variables, **kwargs)

@dataclass
class CompiledPrompt:
    messages: list            # [{"role": ..., "content": [{"type": "text", "text": ...}, ...]}, ...]
    model: dict               # as saved
    tools: list               # as saved
    response_format: dict | None

A variable you leave out gets its default, or renders empty. A value for a variable the prompt doesn't have throws CompileError, whose details lists every problem. In Python, from trodo import CompileError; in Node, check err.name === 'CompileError'. A template the engine can't parse throws TemplateError.

The ManagedPrompt

What get returns:

NodePythonWhat it does
namenameThe prompt's name.
versionHashversion_hashThe version's hash. Pass it as version to fetch exactly this version.
versionversionThe version's number. 0 for a fallback.
labelslabelsThe labels on this version.
tagstagsThe prompt's tags.
descriptiondescriptionThe prompt's description.
messagesmessagesThe messages, with {{variables}} and placeholders still in them.
modelmodelThe model config.
toolstoolsThe tool definitions.
response_formatresponse_formatThe output format, or null / None for text.
variablesvariablesEach variable's name, and its type and default when set.
isFallbackis_fallbackTrue when this is your fallback, because Trodo couldn't be reached.
compile()compile()See above.

It also carries contentHash / content_hash (a hash of the content alone) and parentHash / parent_hash (the previous version's hash).

list

The prompts in your team, without their messages. Returns an empty list on error.

trodo.prompts.list(): Promise<ManagedPromptSummary[]>
// [{ name, description, version, labels, updatedAt }]
trodo.list_prompts() -> list[PromptSummary]
# PromptSummary(name, description, version, labels, updated_at)

renderTemplate

Render any string with the prompt engine, no prompt needed. It throws on a name it has no value for, unless strict is false, which renders it empty.

import { renderTemplate } from 'trodo-node';

renderTemplate(template: string, variables?: Record<string, unknown>, options?: { strict?: boolean }): string
from trodo import render_template

render_template(template: str, variables: dict | None = None, strict: bool = True, **kwargs) -> str

See Template syntax.

clearCache

Drop every cached prompt, so the next get fetches again. Mostly for tests. It is on the client init returns.

const client = trodo.init({ siteId: process.env.TRODO_SITE_ID! });
// ...
client.prompts.clearCache();
client = trodo.init(site_id=os.environ["TRODO_SITE_ID"])
# ...
client.prompts.clear_cache()

On this page