renderPromptBase function exported ✓ 100.0%

Last updated: 2026-03-01T23:25:47.071Z

Metrics

LOC: 25 Complexity: 4 Params: 3 Coverage: 100.0% (11/11 lines, 83x executed)

Signature

renderPromptBase( prompt: StructuredPrompt<TInput, TOutput>, ): : string

Summary

Renders the static (non-input) sections of a structured prompt into a single text block optimised for token economy. Sections rendered (in order): role → task → output format → rules → examples. Use this inside buildPrompt() implementations and then append the per-invocation input context.

Source Code

export function renderPromptBase<TInput, TOutput>(
  prompt: StructuredPrompt<TInput, TOutput>,
): string {
  const sections: string[] = [];

  sections.push(prompt.persona);
  sections.push(prompt.task);

  if (prompt.outputSchema?.length) {
    const schema = renderOutputSchema(prompt.outputSchema);
    sections.push(
      `Respond ONLY with a JSON object in this exact format — no other text, no markdown, no explanation:\n${schema}`,
    );
  }

  if (prompt.rules.length) {
    sections.push(`Rules:\n${renderRules(prompt.rules)}`);
  }

  if (prompt.examples?.length) {
    sections.push(`Examples:\n${renderExamples(prompt.examples)}`);
  }

  return sections.join("\n\n");
}

Dependencies (Outgoing)

graph LR renderPromptBase["renderPromptBase"] renderOutputSchema["renderOutputSchema"] renderRules["renderRules"] renderExamples["renderExamples"] renderPromptBase -->|calls| renderOutputSchema renderPromptBase -->|calls| renderRules renderPromptBase -->|calls| renderExamples style renderPromptBase fill:#dbeafe,stroke:#2563eb,stroke-width:2px click renderPromptBase "1d807d7283d93d7a.html" click renderOutputSchema "a94ee40c258cb1af.html" click renderRules "cc97a1fb4ee38109.html" click renderExamples "956dec267f8fa83b.html"
TargetType
renderOutputSchema calls
renderRules calls
renderExamples calls

Impact (Incoming)

graph LR renderPromptBase["renderPromptBase"] FieldClassifierInput["FieldClassifierInput"] buildPrompt["buildPrompt"] FieldValueInput["FieldValueInput"] renderSystemPrompt["renderSystemPrompt"] ScriptOptimizerInput["ScriptOptimizerInput"] makePrompt["makePrompt"] FieldClassifierInput -->|uses| renderPromptBase buildPrompt -->|calls| renderPromptBase FieldValueInput -->|uses| renderPromptBase buildPrompt -->|calls| renderPromptBase renderSystemPrompt -->|calls| renderPromptBase ScriptOptimizerInput -->|uses| renderPromptBase buildPrompt -->|calls| renderPromptBase makePrompt -->|uses| renderPromptBase style renderPromptBase fill:#dbeafe,stroke:#2563eb,stroke-width:2px click renderPromptBase "1d807d7283d93d7a.html" click FieldClassifierInput "20ede86d2d3727e6.html" click buildPrompt "866645bc66f61421.html" click FieldValueInput "5ea70ce149b7f9cd.html" click renderSystemPrompt "eaffa002075266b5.html" click ScriptOptimizerInput "426c217d515b02d0.html" click makePrompt "ea0597fcfc9fdb16.html"