Prompt engineering tips and best practice

Crafting effective prompts is crucial for maximizing the potential of generative AI. Discover essential guidance for writing clear and useful prompts, including insights on avoiding common mistakes and optimizing image generation.

Generative AI is emerging as a valuable tool for various purposes such as research, learning, creativity, and interaction. At the heart of a modern generative AI interface lies the prompt, serving as the user’s request to the AI system, aimed at eliciting a desired response.

However, AI has its limitations, and obtaining accurate responses hinges on asking well-formulated questions. Despite their growing capabilities, AI systems lack the human insight and intuition to fully grasp users’ intentions. Crafting effective prompts necessitates precise wording, structured formatting, and clear specifications, often eschewing slang, metaphors, and social nuances inherent in human conversation.

Getting the most from a generative AI system requires expertise in creating and manipulating prompts. Here are some ideas that can help users construct better prompts for AI interactions.

What is the role of a prompt engineer?

At first glance, grasping the concept of a prompt seems straightforward. For instance, users often engage with online chatbots and other AI entities by posing questions and providing responses to address issues, make purchases, seek assistance, or carry out basic business transactions.

However, complex prompts can easily become large, highly structured and exquisitely detailed requests that elicit very specific responses from the model. This high level of detail and precision often requires the extensive expertise provided by a type of AI professional called a prompt engineer.

A proficient prompt engineer possesses the following characteristics

1. Technical Proficiency: They have a strong understanding of AI technologies, including natural language processing (NLP), machine learning, and deep learning.

2. Creativity: They can think outside the box to craft innovative prompts that yield desired outcomes from AI models.

3. Attention to Detail: They pay meticulous attention to the wording, structure, and context of prompts to optimize model performance.

4. Problem-Solving Skills: They can troubleshoot issues and iteratively refine prompts to achieve the desired results.

5. Communication Skills: They can effectively communicate with stakeholders to understand their requirements and convey the capabilities and limitations of AI models.

6. Adaptability: They can adapt to evolving AI technologies and methodologies to stay abreast of the latest advancements.

7. Domain Knowledge: They possess expertise in specific domains or industries, enabling them to tailor prompts to suit unique requirements and contexts.

8. Analytical Thinking: They can analyze model outputs and user feedback to iteratively improve prompt design and model performance.

9. Collaboration: They can collaborate effectively with multidisciplinary teams, including data scientists, engineers, and domain experts, to achieve common goals.

10. Ethical Awareness: They are conscious of ethical considerations surrounding AI technology and ensure that prompts adhere to ethical guidelines and principles.

Tips for better prompts

While any user can interact with an AI tool, crafting effective prompts requires a degree of knowledge and skill. Users must have a clear vision of the desired answer or outcome and a deep understanding of the AI system, encompassing its interface intricacies and limitations.

1. Understand the desired outcome

Successful prompt engineering is largely a matter of knowing what questions to ask and how to ask them effectively. But this means nothing if the user doesn’t know what they want in the first place.

Before a user ever interacts with an AI tool, it’s important to define the goals for the interaction and develop a clear outline of the anticipated results beforehand. Plan it out: Decide what to achieve, what the audience should know and any associated actions that the system must perform.

2. Form matters

AI systems can work with simple, direct requests using casual, plain-language sentences. But complex requests will benefit from detailed, carefully structured queries that adhere to a form or format that is consistent with the system’s internal design.

This kind of knowledge is essential for prompt engineers. Form and format can differ for each model, and some tools, such as art generators, might have a preferred structure that involves using keywords in predictable locations.

Another example of a prompt following a similar format could be:

“Act like” + “create a” + “describe a scenario” + “using the tone of”

Sample prompt:

“Act like a travel blogger who is writing an article for a travel magazine to narrate a thrilling adventure through the Amazon rainforest using the tone of David Attenborough.”

3. Make clear, specific requests

AI is neither psychic nor telepathic. It’s not your best buddy and it has not known you since elementary school; the system can only act based on what it can interpret from a given prompt.

Form clear, explicit and actionable requests. Understand the desired outcome, then work to describe the task that needs to be performed or articulate the question that needs to be answered.

For example, a simple question such as “What time is high tide?”  is an ineffective prompt because it lacks essential detail. Tides vary by day and location, so the model would not have nearly enough information to provide a correct answer. A much clearer and more specific query would be “What times are high tides in Gloucester Harbor, Massachusetts, on August 31, 2023?”

4. Watch for length

Prompts might be subject to minimum and maximum character counts. Many AI interfaces don’t impose a hard limit, but extremely long prompts can be difficult for AI systems to handle.

AI tools often struggle to parse long prompts due to the complexity involved in organizing and prioritizing the essential elements of a lengthy request. Recognize any word count limitations for a given AI and make the prompt only as long as it needs to be to convey all the required parameters.

5. Choose words with care

Like any computer system, AI tools can be excruciatingly precise in their use of commands and language, including not knowing how to respond to unrecognized commands or language.

The most effective prompts use clear and direct wording. Avoid ambiguity, colorful language, metaphors and slang, all of which can produce unexpected and undesirable results.

However, ambiguity and other discouraged language can sometimes be employed with the deliberate goal of provoking unexpected or unpredictable results from a model. This can produce some interesting outputs, as the complexity of many AI systems renders their decision-making processes opaque to the user

6. Pose open-ended questions or requests

Generative AI is designed to create — that’s its purpose. Simple yes-or-no questions are limiting and will likely yield short and uninteresting output.

Posing open questions, in contrast, gives room for much more flexibility in output. For example, a simple prompt such as “Was the American Civil War about states’ rights?” will likely lead to a similarly simple, brief response. However, a more open-ended prompt, such as “Describe the social, economic and political factors that led to the outbreak of the American Civil War,” is far more likely to provoke a comprehensive and detailed answer.

7. Include context

A generative AI tool can frame its output to meet a wide array of goals and expectations, from short, generalized summaries to long, detailed explorations. To make use of this versatility, well-crafted prompts often include context that helps the AI system tailor its output to the user’s intended audience.

For example, if a user simply asks an LLM to explain the three laws of thermodynamics, it’s impossible to predict the length and detail of the output. But adding context can help ensure the output is suitable for the target reader. A prompt such as “Explain the three laws of thermodynamics for third-grade students” will produce a dramatically different level of length and detail compared with “Explain the three laws of thermodynamics for Ph.D.-level physicists.”

8. Set output length goals or limits

Although generative AI is intended to be creative, it’s often wise to include guardrails on factors such as output length. Context elements in prompts might include requesting a simplified and concise versus lengthy and detailed response, for example. Keep in mind, however, that generative AI tools generally can’t adhere to precise word or character limits. This is because natural language processing models such as GPT-3 are trained to predict words based on language patterns, not count. Thus, LLMs can usually follow approximate guidance such as “Provide a two- or three-sentence response,” but they struggle to precisely quantify characters or words.

9. Avoid conflicting terms

Long and complex prompts sometimes include ambiguous or contradictory terms. For example, a prompt that includes both the words detailed and summary might give the model conflicting information about expected level of detail and length of output. Prompt engineers take care to review the prompt formation and ensure all terms are consistent.

The most effective prompts use positive language and avoid negative language. A good rule of thumb is “Do say ‘do,’ and don’t say ‘don’t.'” The logic here is simple: AI models are trained to perform specific tasks, so asking an AI system not to do something is meaningless unless there is a compelling reason to include an exception to a parameter.

10. Use punctuation to clarify complex prompts

Just as humans rely on punctuation to help parse text, AI prompts can also benefit from the judicious use of commas, quotation marks and line breaks to help the system parse and operate on a complex prompt.

Consider the simple elementary school grammar example of “Let’s eat Grandma” versus “Let’s eat, Grandma.” Prompt engineers are thoroughly familiar with the formation and formatting of the AI systems they use, which often includes specific recommendations for punctuation.

Additional prompt engineering tips for image generators

  • Describe the image. Offer some details about the scene — perhaps a cityscape, field or forest — as well as specific information about the subject. When describing people as subjects, be explicit about any relevant physical features, such as race, age and gender.
  • Describe the mood. Include descriptions of actions, expressions and environments — for example, “An old woman stands in the rain and cries by a wooded graveside.”
  • Describe the aesthetic. Define the overall style desired for the resulting image, such as watercolor, sculpture, digital art or oil painting. You can even describe techniques or artistic styles, such as impressionist, or an example artist, such as Monet.
  • Describe the framing. Define how the scene and subject should be framed: dramatic, wide-angle, close-up and so on.
  • Describe the lighting. Describe how the scene should be lit using terms such as morning, daylight, evening, darkness, firelight and flashlight. All these factors can affect light and shadow.
  • Describe the coloring. Denote how the scene should use color with descriptors such as saturated or muted.
  • Describe the level of realism. AI art renderings can range from abstract to cartoonish to photorealistic. Be sure to denote the desired level of realism for the resulting image.

To prevent common pitfalls in prompt engineering

Along with tips to improve prompts, there are several common prompt engineering mistakes to avoid:

  • Don’t be afraid to test and revise. Prompts are never one-and-done efforts. AI systems such as art generators can require enormous attention to detail. Be prepared to make adjustments and take multiple attempts to build the ideal prompt.
  • Don’t look for short answers. Generative AI is designed to be creative, so form prompts that make the best use of the AI system’s capabilities. Avoid prompts that look for short or one-word answers; generative AI is far more useful when prompts are open-ended.
  • Don’t stick to the default temperature. Many generative AI tools incorporate a “temperature” setting that, in simple terms, controls the AI’s creativity. Based on your specific query, try adjusting the temperature parameters: higher to be more random and diverse, or lower to be narrower and more focused.
  • Don’t use the same sequence in each prompt. Prompts can be complex queries with many different elements. The order in which instructions and information are assembled into a prompt can affect the output by changing how the AI parses and interprets the prompt. Try switching up the structure of your prompts to elicit different responses.
  • Don’t take the same approach for every AI system. Because different models have different purposes and areas of expertise, posing the same prompt to different AI tools can produce significantly different results. Tailor your prompts to the unique strengths of the system you’re working with. In some cases, additional training, such as introducing new data or more focused feedback, might be needed to refine the AI’s responses.
  • Don’t forget that AI can be wrong. The classic IT axiom “garbage in, garbage out” applies perfectly to AI outputs. Model responses can be wrong, incomplete or simply made-up, a phenomenon often termed hallucination. Always fact-check AI output for inaccurate, misleading, biased, or plausible yet incorrect information.

The Art and Science of Crafting Prompts

Crafting an effective prompt is both an art and a science. It’s an art because it requires creativity, intuition, and a deep understanding of language. It’s a science because it’s grounded in the mechanics of how AI models process and generate responses.

The subtleties of prompting

Every word in a prompt matters. A slight change in phrasing can lead to dramatically different outputs from an AI model. For instance, asking a model to “Describe the Eiffel Tower”  versus “Narrate the history of the Eiffel Tower”  will yield distinct responses. The former might provide a physical description, while the latter delves into its historical significance.

Understanding these nuances is essential, especially when working with LLMs. These models, trained on vast datasets, can generate a wide range of responses based on the cues they receive. It’s not just about asking a question; it’s about phrasing it in a way that aligns with your desired outcome.
We saw this in our guide on how to use Midjourney to create visuals – the difference between adding weights to your prompts for the term ‘space ship’ can yield either images of sci-fi spaceships or a ship sailing through space`.

Space ship

Ship

Summary

Crafting effective prompts for generative AI requires a nuanced approach that balances precision and creativity. Users must have a clear understanding of their desired outcome and formulate prompts that convey their intentions accurately. This process often involves considering factors such as context, formatting, and language choice to optimize the interaction with the AI model.

Prompt engineers play a vital role in this process, leveraging their technical expertise and problem-solving skills to design prompts that elicit the desired responses. They must possess a deep understanding of AI technologies, including natural language processing and machine learning, as well as domain-specific knowledge to tailor prompts to unique requirements.

Attention to detail is paramount in prompt engineering, as even subtle variations in wording or structure can significantly impact the output generated by AI models. By carefully crafting prompts and iteratively refining them based on feedback and experimentation, prompt engineers can optimize the performance of AI systems and ensure that they deliver accurate and meaningful responses.

In addition to technical proficiency, prompt engineers must also possess creativity and adaptability to navigate the complexities of AI interactions. They may need to think outside the box to devise innovative prompts that yield desired outcomes, while also being flexible enough to adjust their approach based on the specific needs of each use case.

Effective communication skills are essential for prompt engineers to collaborate with stakeholders and convey the capabilities and limitations of AI models. By fostering open dialogue and understanding user requirements, prompt engineers can tailor prompts to meet the diverse needs of different applications and industries.

Ultimately, prompt engineering is both an art and a science, requiring a blend of technical expertise, creativity, and problem-solving skills. By following best practices and leveraging the expertise of prompt engineers, users can maximize the potential of generative AI to achieve their goals and drive innovation across various domains.

Scroll to Top