INCLUDE Prompt
Prompt Engineering - Ensuring Specific Information is Included
Section titled “Prompt Engineering - Ensuring Specific Information is Included”A common requirement in prompt engineering is to ensure that the Large Language Model (LLM) includes specific details, facts, keywords, or phrases in its response. This technique allows for greater control over the generated output, making sure critical information is present and emphasized as needed.
Instructing the LLM to Include Specific Content
Section titled “Instructing the LLM to Include Specific Content”To guide an LLM to incorporate particular information, you need to explicitly state this requirement in your prompt. This can be done by clearly listing the items to be included or by phrasing the instruction in a way that makes their inclusion mandatory for a complete answer.
The basic syntax involves a clear instruction about what must be part of the response. For example:
User: Explain the process of photosynthesis. Make sure your explanation includes the terms: 'chlorophyll', 'carbon dioxide', 'water', 'sunlight', and 'glucose'.
LLM: Photosynthesis is the vital process used by plants, algae, and some bacteria to convert light energy into chemical energy. Here's how it works, incorporating your specified terms:
Plants absorb **sunlight** using a green pigment called **chlorophyll**, which is found in chloroplasts within their cells. Simultaneously, they take in **carbon dioxide** from the atmosphere through small pores on their leaves (stomata) and absorb **water** from the soil through their roots.
Inside the chloroplasts, the captured sunlight energy is used to convert carbon dioxide and water into **glucose** (a type of sugar that provides energy for the plant) and oxygen. The oxygen is then released back into the atmosphere as a byproduct. This glucose serves as the plant's food source, fueling its growth and development.In this example, the user explicitly lists the keywords that must be present in the explanation. The LLM then crafts a response that naturally integrates these terms.
Best Practices for Ensuring Inclusion of Specific Information
Section titled “Best Practices for Ensuring Inclusion of Specific Information”To effectively use this technique:
- Be Explicit and Clear: Clearly list or describe the specific details, facts, keywords, or phrases that must be included. Don’t assume the LLM will infer their importance.
- Use Strong Imperatives: Phrases like “Ensure you include…”, “You must mention…”, or “Your response should cover…” can be effective.
- Contextualize the Inclusion: Explain why these specific items are important if it helps the LLM integrate them more naturally (though often just listing them is enough).
- Limit the Number of Mandatory Items (if necessary): Requesting too many specific inclusions in a short response might make the output feel forced or unnatural. Prioritize.
- Check for Natural Integration: Review the LLM’s output to ensure the specified information is included logically and coherently, not just tacked on.
- Iterate if Needed: If the LLM misses an item or includes it awkwardly, rephrase your prompt or be even more direct about the requirement.
Example Application: Python Implementation
Section titled “Example Application: Python Implementation”Let’s look at a practical example using a Python script with the OpenAI API to instruct an LLM to include specific information in its response.
In this example, the user asks for a summary of a book’s plot and specifies that certain characters and plot points must be mentioned.
import openaiimport os
# Recommended: Set your API key via an environment variable.# openai.api_key = os.getenv("OPENAI_API_KEY")# For this tutorial, using a placeholder. Replace with your actual key.openai.api_key = 'YOUR_API_KEY'
def generate_response_with_inclusions(main_query, items_to_include): include_instruction = "When you answer, make sure to specifically include and discuss the following points or terms: " + ", ".join([f"'{item}'" for item in items_to_include]) + "." prompt_content = f"{main_query} {include_instruction}"
messages = [ {"role": "system", "content": "You are a helpful assistant that pays close attention to user requirements for including specific information."}, {"role": "user", "content": prompt_content} ]
try: response = openai.chat.completions.create( model="gpt-3.5-turbo", # Or a newer model like gpt-4o-mini messages=messages, max_tokens=500, # Adjust as needed temperature=0.7, n=1, stop=None ) return response.choices[0].message.content.strip() except Exception as e: return f"An error occurred: {e}"
# Example Usage:query = "Provide a brief summary of the benefits of a balanced diet."mandatory_points = ["macronutrients (proteins, fats, carbohydrates)", "micronutrients (vitamins and minerals)", "energy levels", "disease prevention"]
summary = generate_response_with_inclusions(query, mandatory_points)print("Summary with Specific Inclusions:")print(summary)Expected Output
Section titled “Expected Output”When the script runs, it will generate a summary about the benefits of a balanced diet, ensuring that the specified terms are included. An example output might be:
Summary with Specific Inclusions:A balanced diet offers numerous benefits for overall health and well-being. When you answer, make sure to specifically include and discuss the following points or terms: 'macronutrients (proteins, fats, carbohydrates)', 'micronutrients (vitamins and minerals)', 'energy levels', 'disease prevention'.
A balanced diet is crucial as it provides the body with essential nutrients for optimal functioning. It ensures an adequate intake of **macronutrients (proteins, fats, carbohydrates)**, which are needed in larger amounts. Proteins are vital for building and repairing tissues, fats provide energy and support cell growth, and carbohydrates are the body's primary fuel source, significantly impacting **energy levels** throughout the day.
Equally important are **micronutrients (vitamins and minerals)**, which are required in smaller quantities but are indispensable for various bodily processes, including enzyme function, immune support, and bone health. Consuming a variety of fruits, vegetables, whole grains, lean proteins, and healthy fats helps ensure a sufficient supply of both macronutrients and micronutrients.
One of the most significant benefits of maintaining a balanced diet is its role in **disease prevention**. Proper nutrition can help reduce the risk of chronic conditions such as heart disease, type 2 diabetes, certain cancers, and obesity. By nourishing your body correctly, you support its natural defense mechanisms and promote long-term health and vitality.Conclusion
Section titled “Conclusion”In this chapter, we explored the technique of prompting an LLM to include specific information in its responses. By clearly and explicitly stating which details, facts, or keywords must be present, you gain greater control over the output and ensure that critical content is not overlooked.
We discussed best practices, such as being explicit, using strong imperatives, and checking for natural integration. The Python example demonstrated a practical way to implement this. This skill is essential for tailoring LLM outputs to meet precise informational requirements in various applications.