_.role
BAML prompts are compiled into a messages
array (or equivalent) that most LLM providers use:
BAML Prompt -> [{ role: "user": content: "hi there"}, { role: "assistant", ...}]
By default, BAML puts everything into a single message with the system
role if available (or whichever one is best for the provider you have selected).
When in doubt, the playground always shows you the current role for each message.
To specify a role explicitly, add the {{ _.role("user")}}
syntax to the prompt
Try it out in PromptFiddle
BAML may change the default role to user
if using specific APIs that only support user prompts, like when using prompts with images.
We use _
as the prefix of _.role()
since we plan on adding more helpers here in the future.
Example — Using _.role()
in for-loops
Here’s how you can inject a list of user/assistant messages and mark each as a user or assistant role: