0 / 0
Tips for writing foundation model prompts: prompt engineering

Tips for writing foundation model prompts: prompt engineering

Part art, part science, prompt engineering is the process of crafting prompt text to best effect for a specific foundation model with specific prompt parameter settings. When it comes to prompting foundation models, there isn't just one right answer. There are usually multiple ways to prompt a foundation model for a successful result.

Use the Prompt Lab to experiment with crafting prompts.

  • For help using the prompt editor, see Prompt Lab.
  • Try the samples that are available from the Sample prompts tab of the Prompt Lab.
  • Learn from documented samples. See Sample prompts.

As you experiment, remember the following tips. They will help you successfully prompt most text-generating foundation models.

Tip 1: Remember that everything is text completion

Your prompt is the text you submit for processing by a foundation model.

For most models, simply asking a question or typing an instruction won't yield the best results. That's because the model isn't answering your prompt, the model is appending text to it.

This image demonstrates prompt text and generated output:

  • Prompt text: "I took my dog "
  • Generated output: "to the park."

Text completion in Prompt Lab

Tip 2: Include all the needed prompt components

Effective prompts usually have one or more of the following components: instruction, context, examples, and cue.

Instruction

An instruction is an imperative statement that tells the model what to do. For example, if you want the model to list ideas for a dog-walking business, your instruction could be: "List ideas for starting a dog-walking business:"

Context

Including background or contextual information in your prompt can nudge the model output in the right direction. Specifically, words that appear in your prompt text are more likely to be included in the generated output.

Examples

To indicate the format or shape that you want the model response to be, include one or more pairs of example input and corresponding output that illustrate the pattern you want the generated text to follow.

Including one example in your prompt is called one-shot prompting, including two or more examples in your prompt is called few-shot prompting, and when your prompt has no examples, that's called zero-shot prompting.

When you prompt models that have been tuned, you might not need to include examples.

Cue

A cue is text at the end of the prompt that is likely to start the generated output on the right path. Remember, as much as it seems like the model is responding to your prompt, the model is really appending text to your prompt or continuing your prompt.

Tip 3: Include descriptive details

The more guidance, the better. Experiment with including descriptive phrases related to aspects of your ideal result: content, style, and length. Including these details in your prompt can cause a more creative or more complete result to be generated.

For example, you can improve the sample instruction by adding descriptive information as follows:

  • Original: "List ideas for starting a dog-walking business"
  • Improved: "List ideas for starting a large, wildly successful dog-walking business"

Example

Before

A prompt with a simple instruction:

List ideas for starting a dog-walking business.

The resulting foundation model output isn't great:

Take care of the dog and walk it in your neighborhood. You can create flyers and put them around the neighborhood, you can also put up ads on websites where dog lovers hang out.

After

A prompt with all of the recommended prompt components:

Instruction:

Based on the following industry research, suggest ideas for starting a large, wildly 
successful dog-walking business.

Context:

Industry research:
***
The most successful dog-walking businesses cater to owners' needs and desires while
also providing great care to the dogs. For example, owners want flexible hours, a
shuttle to pick up and drop off dogs at home, and personalized services, such as
custom meal and exercise plans. Consider too how social media has permeated our lives.
Web-enabled interaction provide images and video that owners will love to share online,
which is great advertising for the business.
***

Example:

Ideas for starting a lemonade business:
- Set up a lemonade stand
- Partner with a restaurant
- Get a celebrity to endorse the lemonade

Cue:

Ideas for starting a large, wildly successful dog-walking business:

The resulting foundation model output is much more useful:

  • Start by doing some basic market research. Interview dog owners in your area and ask them what they would want from their dog walker.
  • Offer a free sample or trial period - like several weeks - so you can see if they are really interested.
  • Give personalized service. Offer to train the owner's dog to get in a proper sit or down for the dog walker. Train the human too!
  • Be friendly and outgoing. Social media is huge and people love to post photos of themselves with their pets.
  • Use technology to help keep costs low, such as using web-enabled interactions. For example, you could offer a coupon on a popular pet food store website.

You can experiment with this prompt yourself in the Prompt Lab. Depending on the foundation model you choose and the prompt parameter settings you use, the output might differ.

Learn more

Parent topic: Prompt Lab

Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more