Writing Effective AI Prompts

Last updated on 2026-07-30 | Edit this page

Estimated time: 22 minutes

Overview

Questions

  • FIXME

Objectives

  • Practice interacting with an AI chatbot
  • Use ggplot2 to plot data
  • Remember to ask followup questions

Starting A Conversation


Callout

An Unpredictable World

Most computer programs are deterministic. Given the same input, they will always produce the same output. So in most software lessons, you can expect the same result when you type along with the instructor.

Generative AI is not deterministic, it is probabilistic, so can produce different results from the same input.

As a result, this class will depend on you and your interaction with your LLM of choice. The instructor can guide and direct you, but the experience is not “right or wrong”.

Imagine that you are an early career researcher. You have spent several months carefully collecting data. But you are now under deadline pressure to analyse the data and produce figures for your next paper. You need to write a script to load the dataset, calculate some statistics and produce visualisations, but you have no idea how to proceed.

Challenge

Exercise

Open a LLM chat window in your web browser, type in and submit the prompt:

Teach me to code

Look at the output generated by the LLM and reflect on the questions:

  1. Is the response meaningful and useful?
  2. Does the response suggest leanring paths for the language you want to learn?
  3. Can you identify what you would need to learn to solve your specific data analysis problem?

Many LLMs produce comprehensive and helpful answers to this prompt. However the responses are very general. At the time of writing, Microsoft Copilot, for example, proposes a 7 month curriculum for learning data science. It also proposes learning paths specifically for Python and Javascript. If you are interested in R or other data science languages, this might not be the most helpful approach.

Some More Precision

LLMs are trained on a large variety of texts, and can produce an endless array of possible responses to prompts. In order to generate the most useful response, we need to submit as clear and expressive a prompt as possible. The previous prompt had promising output, but was too general. Let’s try something more specific:

TODO: Python vs R alternatives {prompt} I need to write a script in python to load data, generate statistics and produce figures. What skills do I need to learn to achieve this?

TODO: Consider very different response structures from different LLMs.

Activity 1: Practice interacting with an AI chatbot


Use a chatbot like https://google.com/ai to understand the value of context

  • How many years are available?
    • “It looks like your question is missing some context”
  • How many years are available in gapminder?
    • Official Gapminder Platform (300 years) vs Gapminder R / Python Programming Package (55 years)
  • How many years are available in https://swcarpentry.github.io/r-novice-gapminder/data/gapminder_data.csv?
    • “There are 12 specific years available in that Software Carpentry Gapminder dataset”

Activity 2: Create your first plot (manually)


Load data

  • Confirm gapminder is loaded via head( gapminder ) or refer to Episode 1

Load ggplot2

Run code

R

ggplot( gapminder, aes( year, gdpPercap ) ) +
    geom_point()

Activity 3: Ask the chatbot to explain the code


This is my first time using R. Can you explain what this code is doing, line by line? ggplot( gapminder, aes( year, gdpPercap ) ) + geom_point()

What follow-up questions do you have? Some possibilities: - How does it know to plot year on the x-axis? - Why does ggplot use +? - Explain the difference between aes in ggplot and in geom_point as simply as you can

Activity 4: Modify the plot with help


This is my first time using R. Modify this code in the simplest way possible so that [insert modification]. Explain what the changes do.

Some possibilities: - Dots are colored by continent - color=continent - Dots are spread out more and don’t overlap - geom_jitter() - The outlier dots are labeled - geom_text( data = subset( gapminder, gdpPercap > 50000 ), aes( label = country ), color = “black” )