Skip to content

PromptContent

python
from elsai_prompts.prompt_manager import PromptContent

Returned by every PromptManager fetch method. Unifies access to the four prompt kinds through one class. Kind-specific accessors raise AttributeError if used on the wrong kind — surfacing bugs at the call site instead of returning empty values.

Construction

You don't construct PromptContent directly — it's produced by the SDK from server responses. The constructor signature is documented for completeness:

python
PromptContent(
    kind: str,
    content: dict,
    *,
    sha: str | None = None,
    version_label: str | None = None,
    prompt_id: str | None = None,
    prompt_name: str | None = None,
    environments: list[str] | None = None,
)

There's also a class method that mirrors how the SDK builds it from the wire payload:

python
PromptContent.from_response(payload: dict) -> PromptContent

Common attributes (all kinds)

AttributeTypeDescription
kindstrOne of "instruction", "f_string", "chat", "structured"
shastr | NoneFirst 12 hex chars of the version's content hash
version_labelstr | NoneHuman-readable label, e.g. "v1.0"
prompt_idstr | NoneUUID of the prompt
prompt_namestr | NoneName of the prompt
environmentslist[str]Environments the version is released to

Kind-specific accessors

Accessors raise AttributeError with a clear message if used on the wrong kind:

python
prompt.template
# AttributeError: '.template' is only available for 'f_string' prompts (this prompt is 'instruction')

Instruction

textstr — The main prompt text. Returns "" if missing.

system_promptstr — Optional system prompt. Returns "" if not set.

python
prompt = pm.get_active_prompt_version("system_intro")
assert prompt.kind == "instruction"

prompt.text             # → "You are a polite customer support agent..."
prompt.system_prompt    # → "" (or the configured system text)

F-string

templatestr — Raw template string with {{variable}} placeholders. Returns "" if missing.

variableslist[dict] — Declared variable specs — list of {name, type, description} dicts.

python
prompt = pm.get_active_prompt_version("translator")
assert prompt.kind == "f_string"

prompt.template     # → "Translate {{text}} from {{from}} to {{to}}"
prompt.variables    # → [{"name": "text", "type": "string", ...}, ...]

Chat

messageslist[dict] — List of {role, content} message dicts with {{variables}} allowed in any body.

variableslist[dict] — Declared variable specs.

python
prompt = pm.get_active_prompt_version("interview_bot")
assert prompt.kind == "chat"

prompt.messages    # → [{"role": "system", "content": "..."}, ...]
prompt.variables   # → [{"name": "topic", ...}, ...]

Structured

basePromptContent — The wrapped base prompt — itself a PromptContent of kind instruction, f_string, or chat.

response_schemadict — The JSON response schema. Empty dict if missing.

python
prompt = pm.get_active_prompt_version("entity_extractor")
assert prompt.kind == "structured"

prompt.base                # → PromptContent (kind: "f_string", say)
prompt.base.template       # → "Extract from: {{text}}"
prompt.base.variables      # → [{"name": "text", ...}]
prompt.response_schema     # → {"type": "object", ...}

render(variables)

python
PromptContent.render(variables: dict | None = None) -> str | list[dict] | dict

Substitute {{variables}} and return the rendered content. Polymorphic by kind:

KindReturnsVariables required?
instructionstrNo (ignored if passed)
f_stringstrYes (missing → empty string)
chatlist[{role, content}]Yes (missing → empty string)
structureddict {base: <rendered>, response_schema: dict}Yes (passed to the base)

variablesdict | None (default: None) — Variable values keyed by name. Values are stringified via str(). Extra keys are ignored. Missing variables substitute as empty string.

Examples:

python
# Instruction
prompt.render()
# → "You are a polite customer support agent..."

# F-string
prompt.render({"text": "Hello", "from": "English", "to": "Spanish"})
# → "Translate Hello from English to Spanish"

# Chat
prompt.render({"topic": "Python"})
# → [
#     {"role": "system",  "content": "You are interviewing about Python."},
#     {"role": "user",    "content": "Start the interview."}
#   ]

# Structured
prompt.render({"text": "Apple released..."})
# → {
#     "base": "Extract from: Apple released...",
#     "response_schema": {"type": "object", ...}
#   }

See Rendering variables( for substitution rules.

__repr__

python
>>> repr(prompt)
"PromptContent(kind='f_string', variables=['text', 'from', 'to'])"

Edge cases and gotchas

Variables are case-sensitive

{{name}} matches the key "name" only, not "Name" or "NAME". If you pass {"Name": ...} and the template expects {{name}}, you get an empty substitution.

Missing variables render as empty string, not as a literal

render({}) on a template with {{x}} produces "" for that span, not {{x}}. This is forgiving by design — wrap with a validator if you want strictness.

render() values are stringified

Numbers, booleans, None all pass through str(). None becomes the literal string "None", which is rarely what you want — normalize before calling.

response_schema is not rendered

Even on a structured prompt, the JSON schema is never substituted. Only the wrapped base prompt is rendered with your variables.

Kind can't be discovered from accessors safely

Don't try: prompt.template; except AttributeError: ... to discover the kind — use prompt.kind directly. The accessor AttributeError is a programming-bug signal, not a discovery API.

See also

Copyright © 2026 elsai foundry.