# Class PromptTemplate

java.lang.Object
com.codename1.ai.PromptTemplate

public final class PromptTemplate extends Object

Trivial `{placeholder}` substitution. Designed for the common "build a prompt from a handful of fields" pattern without pulling in a templating library. For anything more sophisticated (loops, conditionals) just compose strings directly.

    String prompt = PromptTemplate.of(
        "You are an expert {role}. Reply in {style}."
    ).put("role", "tax accountant").put("style", "bullet points").build();

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ChatMessage`
  `asSystem()`
  Convenience: render and wrap as a `ChatMessage` with SYSTEM role.
  `ChatMessage`
  `asUser()`
  Convenience: render and wrap as a `ChatMessage` with USER role.
  `String`
  `build()`
  Renders the final string.
  `static PromptTemplate`
  `of(String template)`
  Starts a template instance.
  `PromptTemplate`
  `put(String key, String value)`
  Binds one placeholder.
  `PromptTemplate`
  `putAll(Map<String,String> map)`
  Adds all supplied placeholder values.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### of

    public static PromptTemplate of(String template)
    Starts a template instance.
    Parameters:
      `template` - text containing optional `{name}` placeholders
    Returns:
      mutable template values bound to the supplied text

  - ### put

    public PromptTemplate put(String key, String value)
    Binds one placeholder. A `null` value renders as an empty string.
    Parameters:
      `key` - placeholder name without braces
      `value` - replacement value
    Returns:
      this template

  - ### putAll

    public PromptTemplate putAll(Map<String,String> map)
    Adds all supplied placeholder values.
    Parameters:
      `map` - replacements keyed by placeholder name; `null` is ignored
    Returns:
      this template

  - ### build

    public String build()
    Renders the final string. Unknown placeholders are left intact (`{like_this}`) so they're easy to spot in test output -- silently dropping them tends to hide bugs.
    Returns:
      rendered prompt text

  - ### asUser

    public ChatMessage asUser()
    Convenience: render and wrap as a `ChatMessage` with USER role.
    Returns:
      rendered user message

  - ### asSystem

    public ChatMessage asSystem()
    Convenience: render and wrap as a `ChatMessage` with SYSTEM role.
    Returns:
      rendered system message