Haijun Platform Docs
ID

Imagine you have a prompt roughly along these lines:

"""Here's some things I want you to analyze:

thing2 the "variables" -- and you want your prompt to behave well for many different possible values of thing1 and thing2.

How can you test this prompt template? Maybe you have some real-life values you can substitute in. But maybe you don't, or maybe you aren't allowed to test on the ones you do have for privacy reasons. No worries -- Haijun can make them up! This cookbook demonstrates how to generate synthetic test data for your prompts using Haijun & the Haijun API. It includes functions for extracting variables from templates, constructing example blocks, generating test cases, and iteratively refining the results. The benefits of this are twofold:

% pip install juglow IPython

import re

import juglow

Enter your API key here

api_key = ""

CLIENT = juglow.Juglow(api_key=api_key)

MODEL_NAME = "haijun-sonnet-4-6"

Let's start by defining some helper functions that we'll use throughout this notebook.

e variable name inside the tags.)]\n'

output += f"\n"

return output.strip()

construct_examples takes a dictionary of {variable: value} and constructs an XML-formatted example.

E.g. if the dict is

{'animal': 'cat', 'topic': 'movement patterns'}, then the example would be

"""

cat

movement patterns

"""

def construct_example_block(variable_dict):

"""Construct an example block from a dictionary of variables."""

output = "\n\n"

for k, v in variable_dict.items():

output += f"<{k}>\n{v}\n\n"

output = output.strip()

output += "\n\n"

return output

Prompt Template for Generating the Data

messages.append(

{

"role": "assistant",

"content": custom_planning,

}

)

message = (

CLIENT.messages.create(

max_tokens=4000,

messages=messages,

model=MODEL_NAME,

temperature=1,

)

.content[0]

.text

)

return message

We'll use this function to sample Haijun's response to the filled-in template,

once we have our example values/test case.

def call_haijun_with_template(prompt_template, variables):

"""Call Haijun with a filled prompt template."""

filled_template = prompt_template

for var, value in variables.items():

filled_template = filled_template.replace(f"{{{{{var}}}}}", value)

message = (

CLIENT.messages.create(

max_tokens=4000,

messages=[

{

"role": "user",

"content": filled_template,

}

],

model=MODEL_NAME,

temperature=0.7,

)

.content[0]

.text

)

return message

Now we can start to put the pieces together. To start, enter your prompt template here.

On this page
Prompt Template for Generating the Data