Skip to main content

Prompt Template

Prompt Template is a common technique used in building AI applications. Most non-trivial prompts are rendered from templates.

A prompt template has placeholders in the prompt. These placeholders will be replaced with values in the runtime, before sending the prompt to an LLM. We can use any template languages to describe a prompt template. The choice of template language depends on the programming language.

Spring AI uses StringTemplate as the template language. By default, { and } are used as delimiters of placeholders in the template.

Below is a simple prompt template with a placeholder count. In the runtime, count will be replaced with actual values.

A simple prompt template
Goal: Generate {count} users