Generative AI and LLMs: How to Write an Effective Prompt?

The rapid rise of generative artificial intelligence has introduced new concepts, tools, and methodologies. To make the most of these technologies, it is essential to understand how they function. A key element in interacting with AI is the prompt, a directive that determines the quality and relevance of the responses generated. This article will guide you through the art of crafting an effective prompt.

Reminder: Generative AI and LLMs

Generative AI is designed to autonomously create content (text, images, videos, music). Its functionality is based on artificial neural networks trained on vast datasets.

Large Language Models (LLMs) are a specialisation of generative AI focused on understanding and producing human language. They predict the most probable words in a given sentence, enabling them to generate coherent responses.

Caution: These models are not designed to verify the truthfulness of information but to generate plausible text.

When an LLM is used as a chatbot for a specific purpose, such as providing assistance on an e-commerce website, a “system prompt” is employed. This is a predefined instruction set by the administrator, over which the end user (for example, a customer seeking after-sales support) typically has no control. The purpose of this prompt is to restrict the chatbot’s responses to queries related to customer service, thereby preventing it from being misused to generate poems, provide weather updates, or answer other unrelated requests.

What is a Prompt?

A prompt is an instruction or question submitted to an AI to obtain a targeted response. Unlike a simple search engine query, a prompt can guide AI by imposing rules, context, or a specific response format.

Example:

  • Basic prompt: “Describe the Eiffel Tower.”
  • Detailed prompt: “Write a 150-word paragraph on the history of the Eiffel Tower, focusing on its cultural and technological impact.”

In some cases, system prompts are predefined to limit the AI’s behaviour, such as in customer service chatbots.

Types of Prompts

Based on Response Openness

  • Open prompt: Gives AI creative freedom.
    • Example: “Imagine a world where AI manages all political decisions.”
  • Closed prompt: Seeks a concise and factual response.
    • Example: “What is the height of the Eiffel Tower?”

Based on Provided Context

  • Simple prompt: Direct instruction without context.
    • Example: “Translate this text into Spanish.”
  • Prompt with example: Provides a model for the response.
    • Example: “Reword this sentence in a more formal tone. Example: ‘Hey’ becomes ‘Hello’.”

Based on Complexity

  • Directive prompt: Specifies the response format.
    • Example: “List the five most popular Python web frameworks in a table.”
  • Interactive prompt: Used in multi-step conversations.

Best Practices in Prompt Engineering

1. Clarity and Precision

AI cannot infer what you expect. Be explicit about:

  • Tone: Formal, casual, technical…
  • Format: List, table, paragraph…
  • Target audience: Experts, beginners…
  • Expected length: Word or sentence count.

2. Providing Context

Giving a clear framework improves response relevance. Example:

  • Without context: “Give me a rhyme for ‘i’.”
  • With context: “I am writing a song about Paris; give me a rhyme for ‘i’.”

3. Using Examples

Examples serve as guidance for AI.

  • Without example: “Define machine learning in simple terms.”
  • With example: “Explain machine learning as if speaking to a 10-year-old. Example: ‘AI learns like a student doing exercises.'”

4. Clearly Stating Constraints

Restricting responses prevents unnecessary digressions.

  • Examples of constraints:
    • “Limit your response to 50 words.”
    • “Use a formal tone.”
    • “Avoid technical jargon.”
    • “Adopt a neutral perspective.”

5. Correct Spelling and Grammar

Errors can mislead AI and affect response quality. Example:

  • Incorrect prompt: “What are the effects of green on the environment?” (AI may interpret “green” instead of “glass”).
  • Corrected prompt: “What are the effects of glass on the environment?”

6. Structuring Your Prompt

A clear layout improves comprehension. Example of an effective structure:

  • AI’s role: “You are a marketing expert.”
  • Context: “We are launching a campaign on social media.”
  • Main instruction: “Generate five engaging post ideas.”
  • Constraints: “Max 150 characters, dynamic tone.”

The best practices presented here come from various sources, including courses provided by Google and Amazon, as well as my personal experience in using generative AIs and LLMs.

Conclusion

Mastering prompts is essential to fully harness the potential of generative AI. Experiment with different approaches, test results, and refine your instructions to obtain increasingly precise and relevant responses.

For further learning, explore resources such as:

Share your experiences and optimisations in the comments !

Leave a Reply

Your email address will not be published. Required fields are marked *

  • About us
  • Services
  • Products
  • Blog
  • Contact