Prompt Engineering — Best Practices

M. Haseeb Hassan
Level Up Coding
Published in
6 min readApr 14, 2024

--

Super smart chatbots, like ChatGPT and Claude 3, are everywhere these days! They’re used by all sorts of people to get things done, both at work and at home. These chatbots are like super helpful assistants that can tackle many different tasks. Whether you need help with work stuff or want a little assistance in your personal life, these chatbots are becoming a cornerstone of our daily routines. This article delves into prompt engineering, providing best practices and a few examples to help your business extract maximum value from these large language models.

This article delves into prompt engineering, providing best practices and prompt examples to help your business extract maximum value from the LLMs.
Prompt Engineering — Best Practices

What is Prompt Engineering?

Imagine you’re talking to a super knowledgeable but easily confused friend. Prompt engineering is like giving that friend clear and specific instructions to get the best answer out of them. It’s about crafting the perfect question or statement, using a mix of creativity and knowledge about how the friend thinks. By doing this, you get the most accurate and helpful answer possible. This “prompt engineering” makes communication with AI language models smoother and more effective, just like getting the right info from your friend!

The prompt design is like playing the game of charades!

Why Prompt Engineering?

AI language models are like powerful tools, but they need clear instructions to work their best. That’s where prompt engineering comes in! It’s the art of crafting the perfect question or prompt to get the most accurate and useful answer from the AI. Why is this so important? Here’s why:

  • Think sharper answers: Clear prompts lead to clear answers. No more guessing games about what the AI understood!
  • Save precious time: By giving the AI exactly what you need, you get the answer you want faster, with less back and forth.
  • Tackle tough tasks: Need help with something complex? Good prompts can break down the problem for the AI, making it easier to solve.
  • Happy users, happy life: Imagine an AI that always understands you! Great prompts lead to a smoother, more enjoyable experience for everyone.
  • Get better results: Whether you’re writing code, creating content, or analyzing data, well-crafted prompts can unlock the full potential of the AI for better outcomes.
  • The future is bright!: The more we learn about talking to AI effectively, the more amazing things we can create together.

Best Practices for Prompt Engineering

Crafting effective prompts for AI can improve the quality and relevance of the responses you receive. This expertise requires a nuanced understanding of how AI interprets and processes natural language inputs. Let’s discuss the best practices that can be used to engineer the prompts:

1. Specificity

Getting the best answers from your AI buddy is all about asking clear questions. The more specific you are, the better it understands what you need. Think of it like giving instructions to a friend who’s super smart but needs a little extra detail. The things like background info, format, details, tone and examples can be added to make the prompt more specific.

Prompt Example

Please provide an outline for a comprehensive report that analyzes the current trends in social media marketing for technology companies, focusing on the developments from 2020 onward.

The outline should include an introduction, three main sections addressing different aspects of social media trends, and a conclusion summarizing the findings. Please suggest the types of graphs that could illustrate user engagement trends and list bullet points that summarize key marketing strategies in each section.

2. Data Supply

The key is feeding it real-world information! Think of specific details like numbers, dates, or categories as building blocks for your AI. The more precise the data, the better your AI can understand your questions and craft super-smart answers. This real-world data helps your AI in a few ways: it builds a strong foundation for understanding your request, allows for deeper analysis of complex topics, and even helps your AI make connections and give you better advice. So next time you ask your AI something, don’t be shy about including those specific details!

Prompt Example

Please analyze the sales data from the first quarter of 2024 provided in the attached PDF document. I need a summary that identifies our best-selling product, the overall sales trend, and any notable patterns in customer purchases.

The PDF contains detailed monthly sales units for three products: Product A, Product B, and Product C. After reviewing the data, summarize your findings in a concise paragraph that is suitable for a business meeting. Highlight significant increases or decreases in sales and offer insights into potential factors driving these trends.

3. Focus “What to do”

Forget “don’t do this”! When talking to your AI assistant, focus on what you actually want it to do. This “positive instruction” approach makes things crystal clear for your AI. Instead of the AI having to figure out what you don’t want, it can use its smarts to get you the answer you really need, faster and more accurately

Prompt Examples

Avoid: “Don’t write too much detail. → Use Instead: “Please provide a concise summary.”

Avoid: “Avoid using technical jargon.” → Use Instead: “Use clear and simple language accessible to a general audience.”

Avoid: “Don’t give examples from before the year 2000.” → Use Instead: “Provide examples from the year 2000 onwards.”

4. Chain of Thought

Ever wonder how your AI assistant comes up with its answers? Chain of thought prompting is a way to get your AI to show its work! This technique asks the AI to explain the steps it took to reach its answer, giving you a glimpse into its reasoning process. This is super helpful for complex problems or when understanding “why” is just as important as “what.” By seeing the steps, you can learn how the AI tackles problems and even build your own problem-solving skills!

Prompt Example

Imagine you are a software engineer tasked with optimizing this piece of software for performance:

[Insert code block]

Use the following chain of thought to guide your approach:

a. Performance profiling: Start with how you would profile the software to identify current performance bottlenecks.

b. Optimization techniques: Discuss the specific techniques you would consider to address the identified bottlenecks, such as algorithm optimization, code refactoring, or hardware acceleration.

c. Testing and validation: Describe your method for testing the optimized software to ensure that the changes have had the desired effect and have not introduced new issues.

d. Implementation strategy: Finally, outline how you would safely implement the optimized code into the production environment, ensuring minimal disruption.

Conclude with a summary of the key steps in the optimization process and how you would document and maintain the improvements over time.

With advancements in LLMs usage, new technologies are introduced e.g. Retrieval Augmented Generation (RAG) that implements the chain process which enhanced LLMs responses. You can read more about RAG:

5. Miscellaneous

There are many other best practices like understanding model’s shortcomings, experimental prompting, splitting tasks, etc.

Conclusion

That’s a wrap on our crash course in prompt engineering! By following these best practices, you’ve effectively equipped yourself to have productive conversations with your AI assistant. Remember, AI thrives on clear communication. The more specific and detailed your prompts are, the better your AI will understand your intent and deliver the information you truly need.

Think of your AI assistant as a powerful tool, but one that requires clear instructions to function at its best. By mastering the art of prompt engineering, you’ll not only get the answers you seek, but you might even learn a thing or two along the way.

If you enjoyed the article and wish to show your support, make sure to:

  • 👏 Give a round of applause (50 claps) to help get featured
  • 👥 Follow me on Medium to stay updated with my latest content
  • 📰 Explore more articles on my Medium Profile
  • 🔔 Connect with me on LinkedIn, Twitter, and GitHub

Level Up Coding

Thanks for being a part of our community! Before you go:

🔔 Follow us: Twitter | LinkedIn | Newsletter

🧠 AI Tools ⇒ Become an AI prompt engineer

--

--

I write about Technology, Artificial Intelligence & Machine Learning whereas a non-tech part of me writes about Life, Darkness, Silence and Peace..