Prompt Engineering: Basics, Examples & Best Practices

event

Published

event_available

Updated 3/13/2024

Prompt engineering helps get better outputs from AI systems like ChatGPT and Midjourney. Learn the basics and how to get better results.

prompt engineering image - a robot working on a digital brain

Prompt engineering helps get better outputs from generative AI tools like ChatGPT, Google Gemini, and Midjourney. Experienced prompt engineers know the intricacies and considerations of particular tools, allowing for better and more consistent results.

This quick guide covers the basics of prompt engineering and how to get the best results from AI.

What is Prompt Engineering?

Prompt engineering is the practice of crafting inputs (prompts) that guide AI language models to produce specific desired outputs.

It involves designing, testing, and refining queries and statements to better communicate your intention. Prompt engineering improves the input’s quality and structure, significantly influencing AI systems’ behavior and output.

Importance

In machine learning, prompt engineering is especially important when working with models that generate text, code, or other complex outputs. Unlike traditional computer programming, where the desired behavior of a program is explicitly coded, prompt engineering relies on providing the right cues to a pre-trained AI model, leveraging its learned patterns to achieve a given task.

The process of prompt engineering often requires a deep understanding of the model’s capabilities, the nuances of natural language, and the user’s goals. Prompt engineering is an essential AI skill set. It enables people to use AI tools at their full potential, whether for generating creative content, coding, data analysis, or interactive conversation.

Prompt Examples

Let’s explore prompt engineering with a simple use case. Say you want to create an article about organic coffee beans for your local business…

Ineffective Prompt

You could ask in a simple way like this:

ineffective prompt

But the results would be too generic and need more refinement. While ChatGPT did the task, the article isn’t particularly focused or engaging. For better results, we’ll engineer the prompt into something more specific, requiring less editing.

Effective Prompt

Adding a bit more context and details helps:

effective prompt

With more specific details and context, this input produced a better output that would save extra time and work when creating the article.

Prompt Components

The four main components of an AI prompt are:

  1. Task: The specific action or process you want the AI model to perform. This could be anything from generating text to translating languages to writing different kinds of creative content to answering your questions in an informative way.
  2. Instructions: Clear and concise instructions that tell the AI model what you want it to do. The instructions should be specific enough to avoid ambiguity, but not so specific that they limit the AI model’s creativity.
  3. Context: Any relevant information that can help the AI model understand the task and generate the desired output. This could include background information, examples, or your preferences.
  4. Parameters: Specific elements or variables that govern the output of the AI model. For example, you might specify the desired tone, length, or style of the output.

Use these when designing your prompts to guide your formatting.

Core Components Example

Here is an example of an AI prompt that includes all of these components:

Input

Task: Write a poem about a cat. 

Instructions: The poem should be four stanzas long and have a whimsical tone. Please use the words "fluffy," "purring," and "curious" in the poem. 

Context: Cats are known for their fluffy fur, their purring when they are happy, and their curious nature. 

Parameters: The desired tone is whimsical, the desired length is four stanzas, and the desired words are "fluffy," "purring," and "curious".

This prompt is clear, concise, and informative. It provides the AI model with the information it needs to generate a poem that meets the desired specifications:

Output

In a sunbeam’s gentle clutch, a fluffy feline sprawls,
Whiskers twitch with dreams of chase, in daylight’s golden halls.
With purring motors soft and deep, a lullaby for the hours,
He slumbers in a cotton-wool world, nestled among the flowers.

Curious eyes like lanterns bright, at night they come alive,
Exploring realms of shadowed light, where secret whispers thrive.
A pounce on leaves, a leap so high, a dance on silent feet,
Each rustle and each flutter by, a mystery to greet.

Through the house, this velvet ghost, a whisper on the stair,
Flitting through the rooms it hosts, like dappled dusk air.
Purring friend with padded paws, a companion soft and fair,
Whose gentle purr in stillness draws a solace from thin air.

Oh, to live a life so grand, with such a curious mind,
To find enchantment in the bland, new wonders there to find.
A world within those emerald eyes, where yarns and dreams are spun,
Our fluffy, purring sage so wise, warmed by the lazy sun.

ChatGPT

How to Write Effective Prompts

Writing effective prompts for AI or any interactive system involves clarity, specificity, and an understanding of the system’s capabilities. Here’s a step-by-step process:

  1. Define Your Objective: Clarify what you want to achieve with the prompt. Your goal could be to obtain information, generate content, solve a problem, etc.
  2. Understand the System’s Capabilities: Know what the AI or system you are interacting with can do. This includes its limitations and strengths. It might take some practice prompts, but soon you’ll learn how to get specific results with certain instructions.
  3. Provide Context When Necessary: Include any relevant context that might help the AI understand the prompt better. This could be background information or details relevant to the task.
  4. Structure Your Prompt Logically: Organize the information logically. Start with a brief introduction, followed by the main request, and conclude with any specifics. How you format your prompts will be up to you, but ensure they’re organized and easy to manage.
  5. Include Examples or Templates If Possible: When asking for creative content, providing an example or a template can guide the AI.
  6. Test and Refine: After writing your prompt, test it out. If the results aren’t what you expected, refine the prompt by adjusting the language, adding more context, or being more specific.
  7. Use Feedback Loops: If the system allows for feedback, further refine the prompt. This could be through upvoting, downvoting, or providing corrective input.

Following these steps should clarify your process and provide better, more consistent results from your prompts. The more you craft your prompts, the less you should have to do with outputs. Refining this creates slick workflows with great results.

Best Practices for Prompt Engineering

Here are some tips and tricks for writing and managing prompts:

  1. Iterative Refinement: Start with a broad prompt and then refine it based on the output you get. Iteration can help hone in on the desired result.
  2. Structure Your Prompt: If the task is complex, break down the prompt into structured parts. This can include numbering steps, using bullet points, or separating sections.
  3. Be Concise: While detail is good, overly long or complex prompts can be counterproductive. Strike a balance between brevity and necessary detail.
  4. Prompt for Explanation: If you’re unsure why the AI produces certain outputs, ask it to explain its responses. This can help you adjust your prompts better.
  5. Experiment: Don’t be afraid to try different approaches. Sometimes unconventional prompts can yield surprising and creative results.
  6. Sequential Prompting: For tasks that require multiple steps, consider using a sequence of prompts to guide the AI through the process.
  7. Provide Feedback: Give the AI notes. (If applicable.) Tell it what you like and don’t like so it can adjust accordingly.
  8. Ethical Considerations: Be mindful of ethical implications and biases in your prompts, and strive to promote fairness and avoid harm in the AI’s outputs.
  9. Organize Your Prompts: Keep your favorite prompts somewhere easy to manage and organize, like a Notion database.

If you’re using something like a custom GPT that can refer to knowledge documents, be sure to find a balance between those and prompt details for best results.

Bottom Line

Prompt engineering is essential to interacting with AI systems, particularly in language models. As such, it plays a pivotal role in the usability and effectiveness of AI technologies. Well-engineered prompts can enhance AI performance and outputs, creating more meaningful and productive interactions.

Increase Your Productivity

Streamline workflows and improve efficiency
with our powerful templates and tools.