chapter nine

9 Prompt engineering

 

This chapter covers

  • Learning basic and advanced prompt types (zero-shot, few-shot, structured, etc.)
  • Optimizing instruction refinement and output control
  • Using iterative approaches to improve AI responses
  • Understanding when to use different prompting strategies
  • Creating structured outputs for technical documentation
  • Applying 30 practical prompt engineering techniques for programmers

When Large Language Models (LLMs) emerged on the scene, they changed the way we use artificial intelligence and introduced an important new skill: prompt engineering. This skill involves creating clear and effective instructions for AI models, and it has quickly become necessary for developers, analysts, and tech experts.

Some parts of prompt engineering may seem natural—like how we learned to improve our search engine questions over time. However, learning the details of this skill can make a big difference in the results you get from chat models and LLM-based programming tools. Let’s explore how to create better prompts to get the best results.

In this chapter, we’ll explore how to craft better prompts to save time and be more productive.

9.1 Understanding Prompt Engineering

Imagine you're trying to debug a Python function that's throwing an unexpected error. You could ask an AI:

Fix this code

And you’d probably get back a vague or unhelpful response. Or you could craft a more effective prompt:

9.1.1 Why Prompt Engineering Matters for Developers

9.2 Understanding the Anatomy of a Prompt

9.3 Crafting the Ultimate Prompt

9.3.1 Prompt Engineering Principles

9.4 Fundamental Prompt types

9.4.1 Zero-Shot Prompting

9.4.2 Few-Shot Prompting

9.4.3 Open Ended Prompts

9.4.4 Constrained Prompts

9.4.5 Leveraging Iterative Prompts

9.4.6 Structured Prompts

9.5 Advanced Prompt Types

9.5.1 Chain of Thought Prompting

9.5.2 Recursive Prompting

9.5.3 Context Manipulation

9.5.4 Instruction Refinement

9.5.5 Output Control

9.5.6 Summary

9.6 Prompt techniques for programmers

9.7 Summary