Skip to main content
Language is not text, but a mapping from information to expression.
A prompt in HeavenBase is not a string you paste into an LLM call. It is a callable that turns arbitrary input into the text or messages the model actually sees. This page explains that encoder model, the Markdown helpers that format prompt text, the one-shot layout convention, and how hb.Prompt persists prompts as Capsule-backed workspace rows with first-class translation.

1. Why Prompt Utilities Exist

Without a prompt system, every LLM call site assembles its own prompt text from raw f-strings. The result is prompt drift: one endpoint formats instructions one way, another endpoint uses different phrasing, and there is no single source of truth for what the prompt should say.
This approach treats language as finished text. In practice, a prompt is an encoder: it maps structured information — task context, examples, the current instance — into an expression the model can act on. When prompts live as strings, they are hard to test, hard to version, and impossible to localize without duplicating entire templates. HeavenBase models a prompt as a function that returns rendered text or messages:
The callable is the prompt. Arguments are the payload. The return value is what the LLM reads. That separation keeps logic in code, data in arguments, and the rendered surface stable enough to test and translate. A callable encoder is also more flexible than a format-string template. The function body can branch on payload shape, assemble instance-specific sections, call workspace helpers, or even invoke a meta-prompter LLM that drafts the system text from the actual inputs. String templates cover the simple fill-in-the-blanks case; function prompts cover everything else.

2. Prompt as an Encoder

Think of hb.Prompt as a named encoder — a callable you register, version, and reload. Format-string prompts are one encoding strategy; Python functions are another. Both compile into Capsule-backed callables and share one runtime path.
Prompt is a special case of Capsule. The prompt definition — source code or compiled format string — is captured as a manifest and can be stored as a sys-prompt workspace row. At call time, prompt + payload produces the serialized text the LLM sees:
That split gives you maximum flexibility. The encoder can assemble Markdown sections, pull workspace context, apply translations, branch on input shape, or chain other prompts — whatever the task needs — while the stored definition stays a versioned, loadable object. Because the underlay is Capsule, prompts are persistable, restorable, and auditable like any other HeavenBase entity.
Construction does not write to a workspace. Call prompt.register(...) explicitly, or pass register=True when you want decorator-time registration. Scope register and load with ws=... when prompts belong to a task workspace.

3. Markdown Helpers

Before you reach for hb.Prompt, you often need stable Markdown blocks: headings, lists, code fences, structured examples. HeavenBase keeps these in heavenbase.utils so generated prompt text stays deterministic across runs, reports, and tests.
Use these helpers inside function prompts when you want full control over layout. They are composable building blocks, not tied to any single task shape.

4. One-Shot Prompt Layout

For the common case — a single-turn task with system context, a few examples, and a new instance to solve — HeavenBase provides fast_prompt_section(...). It is a convenience wrapper that turns a conventional section layout into OpenAI-style messages using the Markdown helpers above. The layout follows one principle: system + descriptions + examples + instructions + instance Each example carries inputs, hints, output, expected, and notes. The new instance reuses the same shape but marks its output as TODO, signaling the model what to produce.
This layout works well for one-shot tasks: classification, extraction, structured generation, and similar patterns where you show a few solved examples and hand the model a fresh input. It is less suited to multi-turn dialogue or open-ended agents that assemble context dynamically across turns — those flows are better served by a custom function prompt. Pass separate_system=True when the target LLM path should receive a dedicated system message instead of one user message containing all sections.

5. Function Prompts

Decorate a Python function when the encoder logic should stay in code and persist as a Capsule-backed callable. The function body is your encoder; call arguments are the payload.
Accept *, tr=str in the signature when the prompt contains user-facing phrases. HeavenBase injects a bound translation function at call time so localized text flows through the same encoder without forking the function.

5.1. Compose Encoders

Function prompts can call other prompts, layout helpers, and LLMs in one encoder. A toy meta-prompter pattern: a one-line format-string prompt drafts the system section; fast_prompt_section(...) assembles the one-shot body from examples and the new instance.
The first variant keeps meta-generation inside HeavenBase prompts. The second delegates system drafting to another LLM while the outer encoder still owns the final layout. Both return the user message content that the downstream task LLM should see.

6. Format-String Prompts

Passing a string to hb.Prompt(...) creates the simplest encoder: a compiled format string with placeholder substitution. It uses the same Capsule-backed callable path as function prompts, but the body cannot run arbitrary logic. Use it for short, stable patterns; reach for a function prompt when the encoder needs branching, composition, or meta-generation.
Use a short format string without tr_keys when only the full string needs translation:

7. Load, List, and Version Prompts

Prompts are loaded by dotted name, compact version ref, or row id:
Latest-version selection considers active rows only. Tombstoned rows are hidden from default loads and lists. Register in a workspace when you want the prompt stored as a sys-prompt row:
Prompt rows can restore executable Capsule manifests. Load persisted prompts only from workspaces you trust.

8. Translation as a First-Class Concern

Localization should not require maintaining parallel prompt files. HeavenBase makes translation a first-class part of the prompt surface through the tr argument and prompt.tr. Every prompt call resolves language in this order: explicit lang=..., the prompt object’s bound lang, the current CM_HVNB config scope at heavenbase.prompt.lang, then main_lang. The bound tr function applies that language to source phrases inside the encoder:
Pass tr=... to fast_prompt_section(...) to translate section titles and list items the same way. Function prompts receive tr automatically when the signature declares it. Translation rows live as queryable sys-translation entities in the same workspace. Reach them through prompt.tr:
Lookup checks exact rows first, then source patterns with {placeholder} captures. If no translation is found, HeavenBase returns the source text for elicit="none". elicit="llm" is reserved and raises NotImplementedError in this release.
Translation is available from heavenbase.extensions.prompt for lower-level code, but the root import heavenbase as hb surface keeps translation under Prompt.tr.

9. Persist Agent Instructions

Combine fast_prompt_section(...) with hb.Prompt when agent instructions should persist with the task workspace. The function encoder wraps the one-shot layout; registration stores the callable as a versioned row.

10. CLI

Function prompt creation is Python-only. The CLI create command creates format-string prompts.

Summary

  • Model prompts as encoders — callable functions that map input data to LLM-facing text, not as static strings.
  • hb.Prompt is a Capsule special case: prompt + payload produces the final serialized output, and the encoder itself is persistable.
  • Prefer function prompts when the encoder needs logic, composition, or meta-generation; use format-string prompts for simple substitution.
  • Use Markdown helpers for stable text blocks; use fast_prompt_section(...) for the standard one-shot layout when it fits.
  • Pass tr through encoders and fast_prompt_section(...) so localization stays in the same code path as rendering.

Further Exploration

Related resources:
  • Agents - how prompts fit agent memory and MCP tools.
  • Capsules - how function prompts are captured and restored.
  • LLM Overview - how prompts flow into hb.LLM.
  • Configuration - prompt language defaults under heavenbase.prompt.lang in CM_HVNB