Prompt engineering workflow diagram for LLM optimization

Prompt engineering is a crucial skill for effectively working with Large Language Models (LLMs). This guide covers the basics of creating effective prompts that produce high-quality results, save time, and reduce costs.

Goals

  • Improve the output quality of your LLM
  • Reduce work time by getting better results faster
  • Lower costs with LLMs by optimizing prompt efficiency

The 5 Essential Elements of a Great Prompt

  • 1. Task: The core action the LLM will perform. (example: “Generate an email response to my client”)
  • 2. Context: Who this task is for, why it's needed, and why it matters (example: “This email is for a high priority corporate client”)
  • 3. Persona: The role or expertise level the LLM should assume (example: “Act as a senior CRM specialist”)
  • 4. Format: How the output should look and be structured (example: “The response needs formal tone, bullet point features presentation and must have no more than 300 words”)
  • 5. Training Examples: Give examples of what you want (can be links or text in the prompt)

Common Mistakes to Avoid

  • Avoid general constraints: Don't add blockers (example: “don’t use technical jargons and don’t use mathematical formulas”)
    Instead: “Explain this concept for a non technical person, with start to end follow through details”
  • Avoid generalistic prompts: “Give me a landing page”
    Instead: “Generate me a landing page for my restaurant business. Base the design on the examples: link1, link2, link3. Use a neutral marine blue palette with wine-red highlight items and fade in images”
  • Avoid empty/vague prompts: “Fix the error”
    Instead: “Fix the error on line 54 – 58, the error details: -paste error details- . Avoid modifying other parts of the document/code, and do not install new libraries for this fix”

Step-Back Prompting

Basic prompts will give existing/basic concepts as responses:

Example: “Suggest me a new side hustle” > You can try affiliate marketing

Instead: “I am an electrical engineer, work 9-5, have 2 hours per day free and want to generate about 500 more per week. I consider lecturing, creating a product, doing consulting work or working on electrical safety inspections. Please analyze the market size for these in my region and how feasible each of these are for my profile.”

Also: Ask LLM: “List 10 business ideas that demand less than 2 hours per day that are related to electrical engineering and rank them in terms of ROI and effort demand”

Persistent AI Agents

Creating persistent AI agents that maintain context and expertise can be done in several ways:

  • In the beginning of the prompt: “Act as a Software Architect”
  • Create a reference document: .txt or .md document detailing the role and expertise
  • Use specific agents: In ChatGPT, Claude, and other platforms, there are specific agents for some tasks - explore them

Meta Prompting

Ask the LLM to generate a prompt for you prior to proceeding to the main task:

“I want you to act as an expert prompt engineer. My goal is to create an app that uses weather forecast to plan travels and activities in order to improve vacation experience. Please generate a prompt for me with all the details I need to provide the LLM to start implementing this task. Make the implementation organized in milestones, each milestone needs to be tested before the next milestone begins. I also need a clear definition of success.”

Prompting LLM to Clarify Missing Details

You can also ask the LLM to clarify important information before generating a prompt:

“I want you to act as an expert prompt engineer. My goal is to create an app that uses weather forecast to plan travels and activities in order to improve vacation experience. Please generate a prompt for me with all the details I need to provide the LLM to start implementing this task. Make the implementation organized in milestones, each milestone needs to be tested before the next milestone begins. I also need a clear definition of success. Before you generate the prompt, please clarify with me important information necessary for a complete prompt and project. After I clarify and approve, then I will prompt you to proceed with the prompt generation.”

Restricting Context

Often LLMs will research a wide context base before generating a response. You can restrict the context to avoid high token or context window usage:

Example: “Implement a new function that fetches data from PokemonAPI and presents a random set of 10 Pokémons for the user to view. The chosen Pokémons will be saved in the database (this function must be implemented exactly as described). For this function use only main.py, fetcher.py, models.py and pokemon.py documents. Do not install new libraries and do not extend the context outside of the mentioned files.”

References

https://www.youtube.com/watch?v=riO3e-FBieA