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>| Option | Default | What it does |
|---|---|---|
label | production | Follow this label. |
version | Pin a version: its hash (full or a short prefix) or its number. Not with label. | |
cacheTtlSeconds | 60 | How long a fetch stays fresh. 0 fetches every time. |
fallback | { messages, model?, variables? }, used when nothing is cached and Trodo can't be reached. | |
recordVariables | false | Record the values each compile receives on the span. See Traceability. |
maxRetries | 2 | Retries 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| Argument | Default | What it does |
|---|---|---|
label | production | Follow this label. |
version | Pin a version: its hash (full or a short prefix) or its number. Not with label. | |
cache_ttl_seconds | 60 | How 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_retries | 2 | Retries on a failed fetch, at most 4. |
record_variables | False | Record 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 | NoneA 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:
| Node | Python | What it does |
|---|---|---|
name | name | The prompt's name. |
versionHash | version_hash | The version's hash. Pass it as version to fetch exactly this version. |
version | version | The version's number. 0 for a fallback. |
labels | labels | The labels on this version. |
tags | tags | The prompt's tags. |
description | description | The prompt's description. |
messages | messages | The messages, with {{variables}} and placeholders still in them. |
model | model | The model config. |
tools | tools | The tool definitions. |
response_format | response_format | The output format, or null / None for text. |
variables | variables | Each variable's name, and its type and default when set. |
isFallback | is_fallback | True 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 }): stringfrom trodo import render_template
render_template(template: str, variables: dict | None = None, strict: bool = True, **kwargs) -> strSee 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()Traceability
Every model call records the prompts and exact versions it ran, fallbacks included, so a trace always shows what ran even after a label moves. Optionally, the values it was compiled with too.
FAQ
Common questions about Trodo prompts: shipping without a deploy, labels and versions, compile errors, braces, history, caching, tools, and who can edit.