Effective Prompt Engineering for Large Language Models

by Duncan Miller on October 24, 2023
Large language models like ChatGPT have wide-ranging applications in various business operations. For employees in companies with language models trained on proprietary data, writing effective prompts is essential to unlock the full potential of these AI tools. In this article, we will explore the best practices for crafting prompts that yield accurate and valuable responses from a company-specific language model, whether you're dealing with HR policies, product specifications, company documentation, design procedures, requests for proposals, marketing materials, or contracts.

When you use a business-tuned LLM, think of giving instructions to another person, say someone who is smart but doesn't know the specifics of your task. When an LLM fails to give a helpful response, it's often because the instructions weren't clear enough. For example, if you were to say, "Please write me something about Freshmint Plus Mouthwash" this is quite vague. Instead, it can be helpful to be clear about whether you want the text to focus on the product features, its competitive advantages its history, or something else. Also, you might specify what you want the tone of the text to be, maybe it takes on the tone like a professional journalist would write, or that of technical documentation, or is it more of a sales email that you are writing to a prospective customer? That helps the LLM generate what you want. 

To take it a step further, picture yourself asking a fresh college graduate to carry out this task for you, if you can even specify what snippets of text, they should read in advance to write this text about product XYZ, then that is even better sets up that fresh college grad for success to carry out this task for you.

Understand Your Model's Data


Before writing prompts, it's crucial to have a good understanding of the data on which your language model has been trained. Familiarize yourself with company-specific data such as HR policies, product specifications, company policies, documentation, design procedures, requests for proposals, marketing materials, and contracts. Knowing what's in your model's knowledge base will help you write more context-aware prompts.

Write Clear and Specific Instructions


Precision is key when crafting prompts for company-specific language models. Instead of vague or general queries, be clear, specific, and contextual. For instance, if you're seeking information on HR policies, you might write, "What is the company's policy on parental leave for full-time employees?". Note that being clear doesn't mean using the fewest words possible the opposite is true, the more context and information you can provide the model, the better response it will be able to generate for you.

Give the Model Time to Think


By default, the model will try to answer your question as quickly as possible. If it is a very detailed question, this may cause the model to rush and provide a guess, the same way a human might guess if not given the proper time to answer a question. In these situations, you can instruct the model to think longer about a problem, which means it's spending more computational effort on the task. To provide clear instructions to the model you might say things like "take your time", or "read the product XYZ documentation before answering".

Use Delimiters to Improve Clarity of Input


A tactic to help you write clear and specific instructions is to use delimiters to indicate distinct parts of the input. You can use any type of character delimiter so long as clarify to the model what you are using. Some examples I like to use are quotes "text" arrows <text> brackets [text] or dashes -text- again any type of special character is fine. So for example you might write a prompt like this:

I am going to provide you with existing marketing copy from an existing product and I'd like you to create new marketing copy for a new product in the same tone. Your task is to answer in consistent style. Before responding please review the key features and product specifications of the new product. 

<product>: AeroGlide Toothbrush
<marketing copy>: Say goodbye to ordinary toothbrushes and embrace the future of dental care with the AeroGlide Toothbrush. This cutting-edge toothbrush combines innovation, performance, and style to give you a dental experience like no other.
<product>: FreshMint Plus Mouthwash

The model may then provide a response like:

Product: FreshMint Plus Mouthwash

Marketing Copy: Step into a world of revitalizing freshness with FreshMint Plus Mouthwash. Redefining your oral hygiene routine, this extraordinary mouthwash unleashes a wave of invigorating minty vitality with every rinse, transforming your everyday experience into something truly exceptional. Emerge from your daily ritual with a smile that's not just clean, but truly fresh and alive.

Outline the Specific Steps to Take


A good tactic is to specify the steps required to complete a task. So for example you might write a prompt like:

I am going to provide you with existing marketing copy from an existing product and I'd like you to create new marketing copy for a new product in the same tone. Your task is to answer in a consistent style. Before responding please review the key features and product specifications of the new product. 

Perform the following actions:
1 - Summarize the following text delimited by double brackets with 1 sentence
2 - Translate the summary into French
3 - Translate the summary into Spanish

Use the following format:
Text: <text to summarize>
Summary: <summary>
Translation: <summary translation>

Text to summarize: [[Step into a world of revitalizing freshness with FreshMint Plus. Redefining your oral hygiene routine, this extraordinary mouthwash unleashes a wave of invigorating minty vitality with every rinse, transforming your everyday experience into something truly exceptional. Emerge from your daily ritual with a smile that's not just clean, but truly fresh and alive.]]

The model may provide a response like:

Summary: FreshMint Plus revolutionizes your daily oral care with an extraordinary burst of minty vitality, leaving you with a genuinely fresh and invigorating experience.

Translation (French): FreshMint Plus révolutionne votre soin buccal quotidien avec une explosion extraordinaire de vitalité mentholée, vous laissant une expérience vraiment fraîche et revigorante.

Translation (Spanish): FreshMint Plus revoluciona tu cuidado bucal diario con una explosión extraordinaria de vitalidad a menta, dejándote con una experiencia realmente fresca y vigorizante.

Use Relevant Keywords


Incorporate relevant keywords and terminology from your company's domain. When dealing with product specifications, for example, ensure that you include key technical terms or product names in your prompts to get the most accurate information.

Provide Necessary Context


Sometimes, your prompts may require additional context to generate accurate responses. If you're referencing a particular document or section of a contract, specify it in your prompt. For instance, "Please provide the quality control standards outlined in Section 3.2 of our manufacturing contract."

Use Positive Statements


When framing your prompts, avoid using negations or double negatives, as AI models can sometimes misinterpret them. Formulate your queries using positive statements to ensure clarity. For example, instead of saying, "Explain any exceptions in our refund policy," you can ask, "What are the conditions for refunds according to our policy?"

Ask Direct Questions


Craft your prompts as direct questions to elicit specific answers. This method is effective in obtaining precise responses when you're looking for straightforward information. For example, if you need to know the pricing details of a product, ask, "What is the Manufacturer's Suggested Retail Price (MSRP) of Freshmint Plus Mouthwash?"

Request Sources to Avoid Hallucinations


It's important to talk about some of the model limitations because it's critical to keep these in mind while you are interacting with large language models. Even though the language model has been exposed to a vast amount of knowledge during its training process, it has not perfectly memorized the information it's seen and it doesn't know the boundary of its knowledge very well. This means that it might try to answer questions about obscure topics and can make things up that sound plausible but are not true. These fabricated ideas are called hallucinations.  

Here is an example of a case where the model will hallucinate something by creating marketing copy for a made-up product name. 

When provided the prompt:

Write some marketing copy for the FreshMint Plus Electric Toothbrush by Atomic 

The model response is:

Elevate Your Dental Care with the SensoPlus Electric Toothbrush by Atomic! 

Precision Meets Innovation: Our cutting-edge toothbrush combines advanced technology with precision engineering, providing you with a superior brushing experience like never before.

As you see, the model gives us a pretty realistic-sounding description of a fictitious product and the reason that this can be kind of dangerous is that it answers confidently even though it's fictitious. Make sure to utilize some of the techniques that we've gone through in this article to try to avoid this when you're crafting your own prompts. This is a well-known weakness of the models and something that engineers are actively working on combating.

Here is a second attempt at the same prompt:

Write some marketing copy for the SensoPlus Electric Toothbrush by Atomic. Please cite your sources.

The model response now is:

I apologize for any confusion, but as of my last knowledge update in September 2021, I do not have access to specific sources or information about a product called the "SensoPlus Electric Toothbrush by Atomic." My previous response was generated based on common marketing principles and is entirely fictional.

One additional tactic to reduce hallucinations, in cases where you want the model to generate answers based on a text, is to ask the model to first find any relevant quotes from the text and then ask it to use those quotes to answer questions. Trying to find ways to ask the model to trace the answer back to the source document is often helpful in reducing these hallucinations.

Iteratively Experiment and Refine


Crafting effective prompts often involves experimentation so if you don't achieve the desired results with your initial prompts refine and iterate. It will likely take a few attempts to find the right phrasing or structure to get the information you need to consider this step part of the process. Follow these steps each time:
  1. Submit your best attempt at a clear and specific prompt
  2. Analyze how the model responds and why the desired result was not provided
  3. Refine and clarify the idea and the prompt
  4. Repeat

The art of writing prompts for company-specific language models is an essential skill for employees who want to harness the full potential of AI tools in their work. Following the steps outlined here can ensure that your interactions with the language model yield accurate and valuable responses. Whether you're seeking responses or help with HR policies, product specifications, company policies, documentation, design procedures, requests for proposals, marketing materials, or contract information, following these best practices will help you make the most of your company-specific language model.
  • Photo of Duncan Miller

    Duncan Miller

    Founder, Software Developer

    Duncan is the founder and lead software developer for OpenShiro. He been running startups since 2006 and has been writing code for over 20 years. Duncan has an MBA from Babson College and lives with his wife and two children in Portland Oregon on an extinct cinder code volcano. He is passionate about artificial intelligence, climate solutions, public benefit companies and social entrepreneurship.

Subscribe to our newsletter

The latest prompt engineering best practices and resources, sent to your inbox weekly.