Skip to content

fix(dotprompt-java): add DataArgument render overloads - #647

Open
pavelgj wants to merge 2 commits into
mainfrom
pj/java-render-dataarg-q5t8n2xw4k
Open

pavelgj wants to merge 2 commits into
mainfrom
pj/java-render-dataarg-q5t8n2xw4k

Conversation

@pavelgj

@pavelgj pavelgj commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

What's new

render now takes a DataArgument, keeping template input, @ context and conversation history in separate fields (as JS, Go and Python already do):

DataArgument data = DataArgument.builder()
    .input(Map.of("question", userQuestion))
    .messages(history)                 // List<Message>
    .context(Map.of("state", state))   // becomes @state
    .build();
RenderedPrompt r = dotprompt.render(source, data).get();
// or: dotprompt.compile(source).get().render(data)
  • Template variables come only from data.input(), @ data only from data.context(), history only from data.messages(). Input keys named messages / context are plain template variables.
  • DataArgument.builder() added (the docs already described it).
  • SpecTest renders through the new path; smoke tests (Java + Kotlin) and the Java docs use it.

Why

render(String, Map<String, Object>) reads template variables, context and messages from the same map. If an app passes user-controlled data as that map, the user can add a messages key and inject a system turn or an arbitrary media URL into the output (no markers involved, so the marker nonce in #644 doesn't cover it), or a context key to set @ data. Raised in review of #644.

API changes (unpublished library)

The Map-based overloads are removed: Dotprompt.render(String, Map[, Map]) and PromptFunction / PromptRefFunction.render(Map[, Map]). The Java library hasn't been published yet (the 0.1.0 publish job failed; nothing on Maven Central), so they're removed rather than deprecated. Migrate by wrapping template variables in DataArgument.builder().input(map) and passing history / context through their own fields.

Not in this PR

Dotprompt.render(String, Map) and PromptFunction.render(Map) put template
variables, context and history in one map: every key became a template
variable, "context" set @ data and "messages" set history. Callers passing
user-controlled input as that map let users inject a system turn, media
URLs or @ data. JS, Go and Python keep these in separate DataArgument
fields.

Add render overloads taking a DataArgument (with a builder) on Dotprompt,
PromptFunction and PromptRefFunction. Template variables come only from
input, @ data only from context and history only from messages, so input
keys named "context" or "messages" are plain variables. The Map overloads
are deprecated and convert to a DataArgument with their old semantics, so
there is a single render path. The spec suite, smoke tests and docs now use
the new overloads.
@github-actions github-actions Bot added documentation Improvements or additions to documentation java kotlin labels Nov 17, 2026
The Java library hasn't been published yet, so instead of deprecating the
Map-based render overloads (which read "messages" and "context" from the
input map as reserved keys), remove them along with their conversion
helpers. DataArgument is now the only way to pass render data: template
variables come from input, @ data from context and history from messages.
Tests and docs use the DataArgument overloads only.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation java kotlin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants