Prompt Engineering from OpenAI

This is a hands-on walkthrough of prompt engineering for developers who want to build applications on top of large language models through the OpenAI API, rather than just chatting with ChatGPT in the browser. It’s hosted by Isa Fulford, from OpenAI, who works through the Jupyter notebook examples, and Andrew Ng, who brings his machine learning background to frame the process and the use cases. Every example uses the gpt-3.5-turbo model and the chat completions endpoint from Python, so you can pause the video and run (and tweak) the code yourself.

What prompt engineering is

Prompt engineering is the practice of writing instructions that steer a language model towards the output you actually want. The video boils it down to two principles:

  1. Write clear and specific instructions. Clear doesn’t mean short: longer prompts often give the model more context and produce more relevant results. The tactics are using delimiters (triple backticks, quotes, XML tags) to mark which part of the input is data, asking for structured output such as JSON or HTML, asking the model to check whether the conditions of the task are met before doing it, and giving it a few examples of the task done well (few-shot prompting).
  2. Give the model time to think. When a task is too complex to answer in one go, the model guesses, just like a person would with a hard maths question. Spelling out the steps, or asking it to work out its own solution before judging someone else’s, gets more accurate answers. In one example, the model grades a student’s wrong answer as correct until it is told to solve the problem itself first.

It also covers the main limitation: models don’t know the edges of their own knowledge, so they can hallucinate plausible but made-up facts, such as a detailed description of a toothbrush that doesn’t exist. One way to reduce this is to have the model find relevant quotes in a source text first and base its answer on them.

What it does

The core message is that there is no perfect prompt, only a good process. Andrew compares it to machine learning development: write a first attempt, look at the result, work out why it fell short, refine and repeat. The example turns a chair’s technical fact sheet into a product description, then iterates on length, audience (furniture retailers want technical details), product IDs, and finally an HTML table. For mature applications, you then test prompts against a larger set of examples instead of just one.

From there, the video goes through the main things a single model can do when prompted well:

  • Summarising: short summaries of product reviews, aimed at a specific team (shipping, pricing), or extracting only the relevant facts instead of summarising.
  • Inferring: sentiment, emotions, whether a customer is angry, the item and brand as JSON, and the topics of an article, all without any labelled training data (zero-shot).
  • Transforming: translating, detecting languages, changing tone (slang to business letter), converting formats (JSON to HTML), and proofreading.
  • Expanding: generating personalised customer-service emails, with a reminder to use this responsibly, to be open that the text came from AI, and to set the temperature to 0 for predictable output or higher for more variety.
  • Chatbots: how the system, user and assistant message roles work, why the whole conversation has to be sent back as context on every call, and building a pizza-ordering chatbot that ends by producing a JSON summary of the order.

Why it matters

This video is a good snapshot of how fast things are moving. I started programming with AI in April 2022, with GitHub Copilot suggesting code from comments and the code around them. Less than a year later, ChatGPT had arrived, and now the conversation is about how to write prompts that get the most out of LLMs and how to control their output as closely as possible. Prompt engineering is the next step after autocomplete: instead of hoping the model guesses what you meant, you learn to tell it exactly what you want, in what format, and how to check the result.

The argument behind this video is about speed and reach. In a traditional machine learning workflow, something like a sentiment classifier means collecting labelled data, training a model and deploying it, and repeating all of that for every new task. With an LLM, you write a prompt and get results almost right away, with one model and one API covering many tasks. Work that would have taken a skilled machine learning developer days or weeks now takes minutes, and it’s open to people who are new to machine learning too. But how reliable those results are depends on the prompt: whether the output can be parsed by code, whether user input can hijack your instructions (prompt injection), and whether the model makes things up. That’s exactly what good prompt engineering addresses.


Share: Link copied to clipboard

Tags:

04 May 2023

Where: Home > Technical > Prompt Engineering from OpenAI