March 13, 2024

Prompt Examples

Prompt Examples

In the preceding segment, we outlined the fundamentals of prompting language models (LLMs).

Now, we'll delve into practical examples to demonstrate the versatility of prompts in executing various tasks, while also introducing essential principles. Learning through examples is an effective method to grasp these concepts. Below are several examples showcasing how strategically designed prompts can facilitate a range of tasks tailored for software developers.

Topics Covered:

  • Text Summarization: Condense lengthy articles or documentation into concise summaries to capture the essence of the content.
  • Information Extraction: Extract specific data points, such as function names, variables, or API endpoints from technical documents or codebases.
  • Question Answering: Generate precise answers to technical queries, ranging from debugging issues to understanding complex algorithms.
  • Text Classification: Categorize text into predefined classes, such as identifying programming languages, sorting bug reports, or organizing documentation topics.
  • Conversation: Develop interactive bots for technical support, peer programming, or tutoring in software development concepts.
  • Code Generation: Create code snippets, functions, or even entire scripts based on specified requirements or pseudocode.
  • Reasoning: Solve logical or algorithmic problems, providing explanations or steps taken to reach a solution.

Text summarization

Text summarization is a pivotal task within the field of natural language processing, offering various applications and approaches. Language models, in particular, excel at distilling articles and complex ideas into concise, digestible summaries. Let's explore a straightforward summarization task through the use of prompts, tailored for software developers.

Imagine you're seeking a condensed explanation of blockchain technology. You might structure your prompt as follows:


Summarize blockchain technology. A:


Blockchain technology is a decentralized digital ledger that records transactions across many computers in a way that prevents alteration, ensuring transparency and security. It underpins cryptocurrencies like Bitcoin and can be used for a wide range of applications beyond finance.

Here, the "A:" serves as a cue in the question-answering format, signaling an anticipated response. While its utility might not be immediately apparent, it's a convention we'll explore in more depth with further examples. Suppose the initial explanation is too detailed, and you prefer a more succinct summary. You could direct the model to compress the information into a single sentence:


Blockchain technology is a decentralized digital ledger that records transactions across many computers in a way that prevents alteration, ensuring transparency and security. It underpins cryptocurrencies like Bitcoin and can be used for a wide range of applications beyond finance.Summarize the above in one sentence:


Blockchain is a secure, decentralized ledger that supports cryptocurrencies and has broad applications beyond financial transactions.

This example demonstrates the model's capability to condense a detailed description into a single, comprehensive sentence. While we haven't delved into optimizing accuracy or exploring more complex instructions, this serves as a foundation for experimentation. Software developers are encouraged to modify and test different prompts to achieve more precise or tailored summaries.

Information Extraction

Language models, beyond their prowess in generating text, are adept at undertaking a variety of natural language processing (NLP) tasks, including classification and information extraction.

Consider this scenario where you need to extract specific details from text data:


In academic publications, it is crucial to detail the involvement of AI technologies, such as ChatGPT, in the research process, including manuscript preparation and data analysis. Authors should disclose the use of any large language models (LLMs) to enable a thorough review by editors and peers, ensuring scrutiny for biases or inaccuracies and proper attribution of sources. Similarly, academic journals should be transparent about their reliance on LLMs, for instance, in the manuscript selection process.Identify the AI technology mentioned in the text:


The AI technology mentioned in the text is ChatGPT.

This example underscores the model's ability to pinpoint and extract relevant information from a given text. While the initial prompt is effective, there's room for refinement to enhance precision or cater to more specific information extraction needs.

This illustrates the flexibility of language models in responding to direct instructions, a feature that AI developers leverage to create sophisticated applications and user experiences. Experimenting with different prompt structures and instructions can unlock even more potent capabilities of these models for specialized tasks.

Question Answering

Optimizing the structure of your prompt is a key strategy for eliciting precise responses from a model, especially in question-answering tasks. Incorporating clear instructions, relevant context, and explicit input and output cues can significantly enhance the quality of the model's answers. While not mandatory, these elements foster a structured approach that often yields more accurate results. Here's an illustration of a well-organized prompt designed for software developers:


Please provide a succinct answer to the question based on the given context. If uncertain, reply with "Unsure about answer."Context: Developed by a team at MIT, the programming language Julia is designed to address the needs of high-performance numerical analysis and computational science. Unlike traditional languages that often compromise on either ease of use or speed, Julia combines the best of both worlds. It has been adopted widely across various scientific domains for its efficiency and readability, marking a significant advancement in the field of computational science.Question: What primary issue does the programming language Julia aim to solve?Answer:


Julia aims to bridge the gap between ease of use and high performance in numerical analysis and computational science.

This example demonstrates how a structured prompt can guide the model to provide a specific and concise answer to a question, leveraging the context provided. Such an approach is invaluable for software developers seeking to extract targeted information or clarify concepts efficiently.

Text Classification

In the realm of text classification, refining your prompt crafting skills is crucial, especially as tasks grow in complexity. Beyond merely issuing commands, understanding how to enrich your prompts with context, input data, or illustrative examples becomes pivotal. This nuanced approach can significantly enhance the model's performance, particularly for nuanced or complex classification tasks.

Let's explore this through a text classification example aimed at software developers:

Initial Prompt:

Determine if the following statement is neutral, negative, or positive.Statement: The software's performance is satisfactory.Sentiment:



In this scenario, the instruction was clear, and the model's response of 'Neutral' aligns with our expectations. However, suppose you require the sentiment label in a lowercase format for consistency in your application. Achieving this precision necessitates a more detailed prompt. Providing explicit examples can guide the model towards the desired specificity. Let's refine our approach:

Refined Prompt:

Classify the sentiment of the following statements as neutral, negative, or positive.Statement: The new update significantly improved the app's usability.Sentiment: positiveStatement: The software's performance is satisfactory.Sentiment:



By including an example with the exact formatting requirement, the model now returns 'neutral' in lowercase, adhering to the specified format.

To illustrate the importance of specificity and the potential pitfalls of ambiguity, consider the following example:

Problematic Prompt:

Categorize the sentiment of the text as nutral, negative, or positive.Text: The integration process was smoother than expected.Sentiment:



Here, the typo in 'nutral' was overlooked by the model, which defaulted to the standard 'Neutral' label. This discrepancy highlights a common challenge: the model's tendency to correct perceived errors towards more conventional outputs. To ensure adherence to unique or unconventional labeling schemes, consider enhancing your prompt with more detailed examples or clarifications:

Solution-Oriented Prompt:

For sentiment classification, use the specific labels 'nutral', 'negative', or 'positive'.Text: The API documentation was exceptionally clear and helpful.Sentiment: positiveText: The integration process was smoother than expected.Sentiment:



In this adjusted prompt, including an example with the unconventional 'nutral' label and specifying the labeling scheme helps steer the model towards the desired output. This method underscores the importance of clarity and example-driven guidance in prompt engineering, especially for software developers seeking precise and consistent results from language models.


One of the fascinating capabilities of prompt engineering is guiding the behavior, intent, and persona of an LLM system, especially valuable in crafting conversational agents like technical support bots or customer service chatbots.

Let's design a conversational interface that delivers responses with a blend of technical depth and clarity, suitable for a software development context. This approach, often termed role prompting, involves explicitly defining the system's behavior through the prompt.

Initial Technical Prompt:

This conversation is with a Developer Support Bot. The bot's responses are detailed and technical.Developer: Hi, what's your function?Bot: Greetings! I am a Developer Support Bot here to assist with your programming queries. How may I assist you today?Developer: How do SSL certificates work?Bot:


SSL certificates serve as digital passports that provide authentication for a website to ensure secure data transfer. They establish an encrypted connection between a web server and a browser, using a public and private key pair. This encryption ensures that any data transmitted remains private and integral.

Now, let's adjust the bot's behavior to cater to beginners or non-technical users, aiming for simplicity in explanations.

Simplified Explanation Prompt:

This conversation is with a Developer Support Bot. The bot simplifies complex concepts for easy understanding.Developer: Hi, what's your function?Bot: Hello! I'm here to make tech stuff easier to understand. What can I help you with today?Developer: What's an SSL certificate?Bot:


An SSL certificate is like a secret code that only your computer and a website can understand. It helps keep any information you send to that website safe from hackers. Think of it like sending a letter in a locked box that only the recipient has the key to open.

By adjusting the prompt, you can tailor the bot's responses to suit the audience's technical proficiency. This demonstrates the power of prompt engineering in creating versatile conversational agents that can adapt their communication style to the user's needs. Adding more examples or adjusting the instruction can further refine the bot's responses, enhancing its utility and user experience.

Code Generation

Code generation stands out as a domain where LLMs excel, with tools like GitHub pilot showcasing their potential. By employing well-thought-out prompts, a wide array of coding tasks can be automated. Here are a couple of examples to illustrate this capability, tailored for software developers.

Starting with a basic task, let's generate a program that prompts the user for their name and then greets them.

Simplified Prompt:

// Generate a program that asks for the user's name and greets them.


name = input("Enter your name: ")
print(f"Hello, {name}!")

In this instance, the programming language wasn't specified, demonstrating the model's versatility.

Now, let's explore a more complex scenario, showcasing the LLM's ability to handle detailed prompts involving database operations.

Advanced Prompt:

Given the database schema:
- Table: departments, Columns: [DepartmentId, DepartmentName]
- Table: students, Columns: [DepartmentId, StudentId, StudentName]
Craft a SQL query to retrieve all students enrolled in the 'Computer Science' department.


SELECT s.StudentId, s.StudentName
FROM students s
JOIN departments d ON s.DepartmentId = d.DepartmentId
WHERE d.DepartmentName = 'Computer Science';

This example underscores the LLM's capacity to interpret complex instructions and generate precise code snippets, provided it's given clear information about the task. By detailing the database schema and specifying the query's objective, the model can produce a functional SQL query tailored to the requirements.


Navigating the complexities of reasoning tasks presents a formidable challenge for current LLMs, despite their advancements. Reasoning, especially in mathematical contexts, is a fascinating domain due to the potential for sophisticated applications arising from LLM capabilities.

While there have been strides in enhancing LLMs' mathematical reasoning, it's crucial to acknowledge that these models often find reasoning tasks particularly taxing. This necessitates the deployment of more refined prompt engineering strategies to coax better performance from the models. We'll delve into these sophisticated techniques in a forthcoming guide. For the moment, let's explore some elementary examples to demonstrate the arithmetic abilities of LLMs.

Basic Arithmetic Prompt:

Calculate the product of 9,000 and 9,000.



Now, let's tackle a more challenging problem.

Initial Complex Prompt:

Do the odd numbers in this list sum up to an even number: 15, 32, 5, 13, 82, 7, 1?


No, the sum of the odd numbers is an odd number: 41.

The initial attempt was incorrect. Enhancing the prompt to guide the model through the problem-solving process step by step can yield more accurate results.

Enhanced Problem-Solving Prompt:

Identify the odd numbers in the list: 15, 32, 5, 13, 82, 7, 1. Then, calculate their sum and determine if the total is odd or even.


Odd numbers: 15, 5, 13, 7, 1
Sum: 41
The sum, 41, is an odd number.

This refined approach significantly improves the model's accuracy by breaking down the task into manageable steps, from identifying odd numbers to summing them and finally determining the nature of the sum. It's worth noting that achieving consistent accuracy on such tasks may require iterative refinement of the prompts, incorporating clearer instructions and possibly examples.

In the next section, we will explore advanced prompt engineering techniques to further enhance LLM performance on reasoning tasks and beyond, aiming for even more sophisticated and accurate outcomes.

Get API Key