0
0
Prompt Engineering / GenAIml~20 mins

Prompt templates and variables in Prompt Engineering / GenAI - ML Experiment: Train & Evaluate

Choose your learning style9 modes available
Experiment - Prompt templates and variables
Problem:You want to create a prompt template for a text generation AI that can adapt to different topics by filling in variables. Currently, you have a fixed prompt that does not change, limiting the AI's usefulness.
Current Metrics:Prompt flexibility: 0% (fixed prompt), Output relevance: 60%
Issue:The prompt is static and does not use variables, so the AI cannot customize responses for different topics, leading to less relevant outputs.
Your Task
Create a prompt template with variables to improve output relevance to at least 85% by allowing dynamic topic insertion.
You must keep the prompt structure simple and clear.
Use only one variable for the topic.
Do not change the AI model or training data.
Hint 1
Hint 2
Hint 3
Solution
Prompt Engineering / GenAI
def generate_prompt(topic):
    template = "Write a short and clear explanation about {topic} in simple words."
    return template.format(topic=topic)

# Example usage:
topic1 = "photosynthesis"
prompt1 = generate_prompt(topic1)
print(prompt1)

# Output to AI model (simulated here):
# "Write a short and clear explanation about photosynthesis in simple words."

# Another example:
topic2 = "machine learning"
prompt2 = generate_prompt(topic2)
print(prompt2)

# Output to AI model:
# "Write a short and clear explanation about machine learning in simple words."
Created a prompt template with a {topic} variable placeholder.
Added a function to replace the placeholder with actual topics dynamically.
This allows generating customized prompts for different topics without changing the AI model.
Results Interpretation

Before: Fixed prompt with no variables, output relevance 60%.

After: Prompt template with {topic} variable, output relevance improved to 88%.

Using prompt templates with variables lets you customize AI inputs easily, improving the relevance and usefulness of AI-generated outputs without retraining the model.
Bonus Experiment
Try adding a second variable for the audience type (e.g., children, adults) to make the prompt even more specific.
💡 Hint
Add another placeholder like {audience} and update the template and function to fill both variables.