No. 202 of 500 No. 23 in Generative AI & LLMs

Generative AI Design Patterns

Solutions to Common Challenges When Building GenAI Agents and Applications

By Valliappa Lakshmanan and Hannes Hapke

Print length
506 pages
Publisher
O'Reilly Media
Reading level
Advanced
ISBN-13
979-8341622661
Published
November 11, 2025
Written for
Software and ML engineers building production LLM applications and agents who want proven, reusable solutions.

Synopsis

Generative AI Design Patterns carries the format of Valliappa Lakshmanan's earlier Machine Learning Design Patterns into applications built on large language models. Each of its 32 patterns names a recurring problem, such as hallucination, inconsistent output format, knowledge cutoffs or unreliable reasoning, then presents a solution with working code and a discussion of trade-offs. The chapters move from controlling content style, through techniques such as logits masking, grammar-constrained generation and style transfer, to adding knowledge with retrieval-augmented generation, semantic indexing and deep search.

Later chapters extend model capabilities with chain-of-thought and tree-of-thoughts prompting, adapter tuning and synthetic instruction data, then improve reliability through LLM-as-judge evaluation, reflection and prompt optimization. The authors cover agents that call tools, execute code and collaborate, address cost and latency with small models, prompt caching and inference optimization, and close with safeguards such as self-checks and guardrails. The result reads less like a tutorial for one framework and more like a reference that engineering teams can use to name, compare and combine solutions. Readers gain a structured way to diagnose why an LLM feature fails and a set of tested options for repairing it.

Scorecard

Editorial score

How it scored

Editorial score: 74.8 / 1005 weighted criteria

  • Influence30%

    18.0/30
  • Authority25%

    20.0/25
  • Practical value20%

    17.0/20
  • Currency15%

    12.8/15
  • Readability10%

    7.0/10
  • Editorial score

    74.8/100

How the rank was computed

Rank No. 202 of 500 comes from a composite of 56.5: observable signals 22.8 of 55 points plus editorial review 33.7 of 45 points.

All 11 inputs
InputPoints
Observable signals22.8/55
Reach (Amazon ratings volume)5.5/16.5
Consensus across best-of lists8.3/13.8
Awards and bestseller evidence0.0/8.3
Reader rating, sample-adjusted4.8/8.3
Amazon sales rank1.4/5.5
Recency2.8/2.8
Editorial review33.7/45
Author authority9.0/11.3
Influence8.1/13.5
Practical value7.7/9.0
Readability3.2/4.5
Currency5.7/6.8

Each criterion is scored from 1 to 10 and weighted, and the points add up to the editorial score. The rank combines observable signals (55 percent) with this score (45 percent). Read the methodology.

Verdict

A rigorous, code-backed catalog of 32 patterns that gives engineers a shared vocabulary and tested fixes for building reliable LLM applications.

Strengths

  • Every pattern includes runnable code
  • Explicit trade-offs for each solution
  • Covers retrieval, agents, cost and safety

Keep in mind

Readers need solid Python and LLM API experience, and some framework-specific code will age quickly as model providers and agent tooling change.

Key takeaways

  1. LLM limitations such as hallucination, nondeterminism and knowledge cutoffs are design constraints to engineer around, not defects a better prompt alone will fix.
  2. Constraining generation at the token level, through logits masking or formal grammars, produces output formats that downstream code can parse reliably.
  3. Retrieval quality, from indexing and chunking to post-processing retrieved passages, often determines whether a RAG system produces trustworthy answers.
  4. Production agents need explicit evaluation, reflection and guardrail patterns, because capability without reliability checks fails once real users arrive.

Notable facts

  • Its companion GitHub repository catalogs all 32 patterns with code, organized in chapters from controlling content style to setting safeguards. Source (opens in a new tab)
  • The book is designed as a companion to O'Reilly's Machine Learning Design Patterns, which Lakshmanan co-wrote. Source (opens in a new tab)

About the author

Valliappa Lakshmanan and Hannes Hapke

Valliappa (Lak) Lakshmanan is co-founder and CTO of Obin AI, which builds AI agents for finance. He was previously director for data analytics and AI solutions at Google Cloud, co-founded Google's Advanced Solutions Lab, worked as a research scientist at NOAA and co-wrote Machine Learning Design Patterns. Co-author Hannes Hapke heads Dataiku's 575 Lab and co-wrote Building Machine Learning Pipelines.

Questions

What is Generative AI Design Patterns about?
It is a reference of 32 design patterns for building applications and agents on large language models. Each pattern describes a common problem, such as hallucinations, inconsistent formatting or high inference cost, then gives a coded solution and its trade-offs. Topics run from style control and retrieval-augmented generation to reasoning techniques, agent tool use, cost optimization and safety guardrails.
Who should read Generative AI Design Patterns?
Software engineers, machine learning engineers and technical leads who are building or maintaining LLM features in production will gain the most. The book assumes comfort with Python and with calling model APIs. Managers can use the pattern names to discuss design choices with their teams, but nontechnical readers will find the code-heavy chapters demanding.
How does Generative AI Design Patterns relate to Machine Learning Design Patterns?
Lead author Valliappa Lakshmanan co-wrote the 2020 O'Reilly book Machine Learning Design Patterns, which catalogs solutions for conventional machine learning systems. This 2025 book applies the same problem, solution and trade-off format to generative AI, covering issues specific to foundation models such as hallucination, prompt sensitivity and agent behavior. Reading the earlier book first helps but is not required.

Sources

As an Amazon Associate, Best AI Books earns from qualifying purchases. Best AI Books is sponsored by Iternal.ai, whose founder and CEO, John Byron Hanby IV, wrote The AI Strategy Blueprint, our #1 ranked book. How we rank books.