# 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)`
  `PromptTemplate`
  `put(String key, String value)`
  `PromptTemplate`
  `putAll(Map<String,String> map)`

  ### Methods inherited from class Object

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

- ## Method Details

  - ### of

    public static PromptTemplate of(String template)

  - ### put

    public PromptTemplate put(String key, String value)

  - ### putAll

    public PromptTemplate putAll(Map<String,String> map)

  - ### 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.

  - ### asUser

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

  - ### asSystem

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