liveBook · Manning

Prompt

As explained in Data Analysis with LLMs

A textual instruction supplied to a language model that specifies a task, context, inputs, and often the desired output format.

A prompt is the input given to a language model. Unlike a model specialized for one task, a general-purpose model needs instructions saying what to do. A useful prompt also supplies the relevant context and data, and specifies the desired answer format. It may include examples of correctly solved inputs. section 1.3.1

Listing 1.1 Prompt for classifying a laptop review
We are considering product reviews for laptops.  #1
For each review, output "satisfied" or "dissatisfied", 
depending on whether the customer is satisfied 
with the product or not.  #2
Examples:
This is a great laptop! I recommend everyone to buy it! 
satisfied  #3
This laptop did not work. I had to return it.
dissatisfied  #4
The screen is too small and it takes too long to start.  #5

This laptop-review prompt establishes the product context, requires one of two labels, shows two labeled examples, and ends with the review to classify. section 1.3.2

For a collection of reviews, keep the task instructions and examples fixed and replace only the review text. A prompt template makes that repeatable: put a placeholder such as [ReviewText] where each review belongs, substitute a review, send the resulting prompt to the model, and save its answer. The requested labels make those answers easier to process. section 1.4.1 section 1.3.1

Database:                                          #1
CREATE TABLE games(rank int, name text, platform text,
year int, genre text, publisher text, americasales numeric,
eusales numeric, japansales numeric, othersales numeric,
globalsales numeric);
Translate this question into SQL query:  #2
[Question]                          #3

A text-to-SQL prompt needs different context: the database definition, an instruction to produce SQL, and the question to translate. [Question] lets the same template serve multiple questions. section 5.2.4

Prompts can contain more than text. A visual question can pair an image with a question; comparing two pictures can request a “Yes” or “No” answer. For video titling, selected frames accompany an instruction to generate a concise title. These uses depend on a model that accepts images. section 6.2.1 section 6.3.1 section 6.4.1

In an OpenAI chat-completion call, task-specific instructions and context can go in a user message. A system message is a separate, optional way to give general guidelines. Prompt wording matters: examples of correct answers can improve performance, but generated results still need to be judged against the task. section 3.4 section 9.11

How Data Analysis with LLMs covers it

How deep it goes
Defines prompt components and works through reusable templates and multimodal inputs, without descending into model internals.
Examples
Uses labeled laptop reviews, a movie-review sentiment question, a database schema and question, and image-based questions.
What it assumes
Introduces prompts from their basic definition before showing Python templates and API messages.
What you can do after
Apply it via OpenAI’s Python library to generate prompts from templates, submit them, and collect classifications.
How it connects
Connects prompts to few-shot learning, prompt templates, chat completion, multimodal input, and text-to-SQL translation.

Also explained in

Compare how 50 books explain prompt →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Analysis with LLMs. The section links point to the parts of the book it draws on.