liveBook · Manning

Few-shot learning

As explained in Software Testing with Generative AI

Few-shot prompting is a prompting technique that supplies a small number of explicit examples to clarify instructions and guide a generative model's output.

Few-shot prompting supplies a small number of explicit examples alongside instructions, helping a generative model interpret the intended output format and the meaning of its placeholders. A prompt without examples is zero-shot prompting. section 2.4.5

Apply the technique by:

  • State the task and required output format before showing examples. section 2.4.5
  • Provide at least two representative examples when guiding a new prompt. section 2.4.5
  • Use examples to clarify natural-language placeholders, templates, quality characteristics, or response structure. section 2.4.5 section 4.2.2
  • Add delimiters and relevant context, then inspect the generated result rather than assuming its quality. section 4.2.1 section 8.1.2

Generating exploratory test charters

A prompt asks for three booking-date charters in the form “Explore <Target> using <Resource> to discover <Information>.” Examples such as “Explore user permissions using different users to discover permission risks” guide outputs about date validation, time zones, and booking conflicts. section 2.4.5

Guiding analysis and data generation

A risk-analysis prompt demonstrates the format “Risk - Quality Characteristic - Explanation,” while a SQL prompt supplies CREATE and INSERT statements for related tables. The examples and schema context help preserve relationships such as room identifiers and foreign keys. section 4.2.2 section 6.2.2

###
public BookingResult createBooking(Booking bookingToCreate) throws
➥SQLException {
    if(dateCheckValidator.isValid(bookingToCreate.getBookingDates())) {
        if (bookingDB.checkForBookingConflict(bookingToCreate)) {
            return new BookingResult(HttpStatus.CONFLICT);
        } else {
            CreatedBooking createdBooking = 
            ➥bookingDB.create(bookingToCreate);
 
            if(bookingToCreate.getEmail() != null && 
            ➥bookingToCreate.getPhone() != null){
                MessageBuilder messageBuilder = new MessageBuilder();
                Message message = messageBuilder.build(bookingToCreate);
 
                messageRequests.postMessage(message);
            }
 
            return new BookingResult(createdBooking, 
         ➥HttpStatus.CREATED);
        }
    } else {
        return new BookingResult(HttpStatus.CONFLICT);
    }
}
###

Use the booking method as a concrete input for a few-shot risk prompt, with the supplied example establishing the expected risk category and explanation format. section 4.2.2

How Software Testing with Generative AI covers it

How deep it goes
Demonstrates prompt construction, examples, delimiters, context, and result review but stops short of guaranteeing correct outputs.
Examples
Uses booking-date charters, user-story questions, code-risk reports, SQL records, and report-calendar test ideas.
What it assumes
Assumes familiarity with the task and desired format while teaching the model that format through explicit examples and context.
What you can do after
Apply it via prompts to elicit consistently formatted testing artifacts and then evaluate, refine, or discard the results.
How it connects
Connects prompt engineering with delimiters, structured output, exploratory testing, test charters, SQL, and quality characteristics.

Also explained in

Compare how 18 books explain few-shot learning →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Testing with Generative AI. The section links point to the parts of the book it draws on.