Most people using AI tools don’t realize how much the quality of their results depends on how they ask for them. It’s like trying to get directions in a foreign country with just a few phrases from high school language classes. They might get there, but the journey is much harder than it needs to be. Prompt engineering, the art of crafting effective prompts, is crucial for anyone working with large language models (LLMs). However, it’s not always obvious how to do it well. While demoing Flyder to clients, I noticed users often struggled with creating effective prompts. That’s why I’m writing this post. Fortunately, two techniques can dramatically improve results: the CO-STAR framework and the use of delimiters. These simple ideas make a big difference.
The CO-STAR Framework: A Structured Approach to Prompt Design
Developed by GovTech Singapore’s Data Science & AI team, the CO-STAR framework provides a structure for creating prompts that elicit optimal responses from LLMs. Let’s break down what CO-STAR stands for:
- Context: Provide background information on the task
- Objective: Define the specific goal or task for the LLM
- Style: Specify the desired writing style
- Tone: Set the attitude of the response
- Audience: Identify who the response is intended for
- Response: Specify the desired output format
By addressing each of these elements in your prompt, you ensure that the LLM has all the necessary information to generate an effective response.
Examples of CO-STAR in Action
1. Mobile App Marketing
Context: We're launching a new AI-powered fitness app that creates personalized workout plans. Objective: Create a blog post to encourage tech-savvy fitness enthusiasts to download and try the app. Style: Informative yet exciting, like a cutting-edge tech blog. Tone: Enthusiastic and knowledgeable. Audience: Millennials interested in both fitness and technology. Response: A 500-word blog post with subheadings and a call-to-action.
2. Technical Writing
Context: We're developing documentation for a new Python library for data visualization. Objective: Write an introductory section explaining the key features and benefits of the library. Style: Clear, concise technical writing suitable for a programming manual. Tone: Professional and informative Audience: Intermediate to advanced Python developers familiar with data science concepts. Response: A 200-word introduction suitable for the first page of the documentation.
3. Creative Writing
Context: We're creating a children's book about a young robot learning to make friends. Objective: Write the opening paragraph of the story, introducing the main character and setting. Style: Whimsical and engaging, similar to Dr. Seuss or Roald Dahl. Tone: Lighthearted and fun Audience: Children aged 6-10 years old. Response: A vivid and captivating opening paragraph of about 100 words.
Delimiters: Adding Structure to Your Prompts
While the CO-STAR framework helps you organize the content of your prompt, delimiters provide a way to structure the prompt itself. Delimiters are special tokens that help the LLM distinguish different parts of your prompt as distinct units of meaning.
There are two main types of delimiters you can use:
- Special Characters: These can be any sequence of characters that wouldn’t typically appear together, such as
###
,===
, or>>
. - XML Tags: These are particularly effective because LLMs have been trained on a lot of web content in XML format.
Examples of Delimiters in Action
1. Using Special Characters for Sentiment Analysis
Classify the sentiment of each conversation in <<<CONVERSATIONS>>> as 'Positive' or 'Negative'. Give the sentiment classifications without any other preamble text. ### EXAMPLE CONVERSATIONS [Agent]: Hello, thank you for calling our support line. How may I assist you today? [Customer]: I've been on hold for 30 minutes! This is ridiculous. [Agent]: Good afternoon! How can I help you today? [Customer]: Wow, that was fast! I can't believe how quickly you solved my problem. ### EXAMPLE OUTPUTS Negative Positive ### <<< [Agent]: Welcome to our support. How can I help you today? [Customer]: I'm having trouble with my recent purchase. It's not working as expected. [Agent]: Good afternoon! What can I do for you? [Customer]: Just wanted to say thank you for the amazing product. It's perfect! >>>
2. Using XML Tags for Recipe Generation
Generate a recipe based on the following parameters: <meal-type> Breakfast </meal-type> <main-ingredient> Avocado </main-ingredient> <dietary-restrictions> Vegan, Low-carb </dietary-restrictions> <cooking-method> No-cook </cooking-method> <difficulty> Easy </difficulty> <recipe> [Your generated recipe should go here] </recipe>
3. Using Special Characters for Code Explanation
Explain the following Python code in simple terms: === def fibonacci(n): if n <= 1: return n else: return fibonacci(n-1) + fibonacci(n-2) result = fibonacci(10) print(result) === Your explanation:
Combining CO-STAR and Delimiters
The real power comes when you combine these techniques. Use CO-STAR to make sure you’re providing all the necessary information, and use delimiters to structure that information clearly. It’s like the difference between handing someone a messy pile of papers and a well-organized folder.
Example of Combining CO-STAR and Delimiters
Let’s look at an example of how we might combine these techniques to create a prompt for generating a product description:
Generate a product description based on the following parameters: <context> Our company, EcoTech, is launching a new smart thermostat that uses AI to optimize home energy usage. </context> <objective> Create a compelling product description that highlights the environmental benefits and cost savings of our smart thermostat. </objective> <style> Blend technical accuracy with approachable language, similar to how Apple describes its products. </style> <tone> Enthusiastic and forward-thinking, emphasizing innovation and environmental responsibility. </tone> <audience> Environmentally conscious homeowners, aged 30-55, who are comfortable with technology but not necessarily tech experts. </audience> <response> A 200-word product description suitable for our website's product page, including: - A catchy headline - 3-4 key features or benefits - A brief explanation of how the AI technology works - A call-to-action encouraging purchase or learning more </response> ### EXAMPLE OUTPUT STRUCTURE: [Catchy Headline] [Opening paragraph introducing the product and its main benefit] [Bullet points or short paragraphs for 3-4 key features/benefits] [Brief explanation of AI technology] [Closing paragraph with environmental impact] [Call-to-action] ### Generate the product description based on these parameters:
In this example, we’ve used XML-style tags to clearly delineate each component of the CO-STAR framework. This makes it easy for the AI to understand and utilize each piece of information. We’ve also used the ### delimiter to separate the example output structure from the rest of the prompt.
By combining these techniques, we provide the AI with:
- A clear understanding of the context and goals (CO-STAR)
- Specific guidance on the style and tone to use (CO-STAR)
- Information about the target audience (CO-STAR)
- A structured format for the response (Delimiters)
- An example of how the output should be organized (Delimiters)
Practical Benefits of Refined AI Interaction
Mastering these techniques takes practice. You’ll need to experiment to see what works best for different tasks. But the payoff is worth it. You’ll get better results, more consistently, with less frustration.
And there’s a broader point here. These techniques are really about communication. They’re about learning to express your ideas clearly and completely. That’s a valuable skill far beyond just working with AI. It’s useful anytime you need to explain something complex, whether to a person or a machine.
In a world where we’re increasingly working alongside AI, the ability to communicate effectively with these systems is becoming as important as the ability to write clear emails or give good presentations. It’s a new kind of literacy. And like any kind of literacy, it’s worth taking the time to learn it well.
Contact the Author
Bill Antoniadis
[email protected]
If you would like to speak to someone at Streamline about a project, please contact us any time.