ctx (accessing metadata)
If you try rendering {{ ctx }}
into the prompt (literally just write that out!), you’ll see all the metadata we inject to run this prompt within the playground preview.
In the earlier tutorial we mentioned ctx.output_format
, which contains the schema, but you can also access client information:
Usecase: Conditionally render based on client provider
In this example, we render the list of messages in XML tags if the provider is Anthropic (as they recommend using them as delimiters). See also template_string as it’s used in here.