Open Reader

Context Engineering With DSPy

completed 1:09:29 Oct 30, 2026 Watch on YouTube

Current Status

completed

Video ID

k1mmJaqQky0

RAG / Chat

Enabled
Context Engineering With DSPy
Description

Subscribe to Every: https://every.to/subscribe?utm_source=livestream&utm_content=dspylive Get Mike Taylor's book Context Engineering with DSPy: https://www.oreilly.com/library/view/context-engineering-with/0642572261603/

Summary

Generated by gpt-5.6-terra

At-a-Glance

  • Verdict: Watch fully
  • Core thesis: DSPy turns LLM applications from brittle, hand-authored prompts into portable, typed programs that can be systematically optimized against reusable evaluation data as models and inference strategies change.
  • Why it matters: For agent and AI-ops systems, it offers a practical control layer for separating task specification, evaluation, optimization, model routing, structured outputs, and production selection—making performance and cost tradeoffs measurable rather than anecdotal.
  • Best use: Use it as an architecture and operating-model tutorial: adopt the signature/eval/optimizer pattern for high-value agent skills, then use the RLM and Flex discussion to inform longer-context and adaptive workflow design.

Executive Summary

Mike Taylor of Every, with Compound co-founders Drew and Isaac—who maintain DSPy—argues that prompt engineering should be treated as an implementation detail rather than the durable artifact. In DSPy, the durable artifact is a typed task definition: a signature with a task description, named inputs, and named outputs. DSPy then handles provider formatting, structured output enforcement, prompt construction, optimization, and migration across models. The speakers' central claim is that a task can remain stable while the underlying model, prompt format, inference-time strategy, and cost-performance configuration continually change.

The practical walkthrough builds a text “humanizer” and an AI-text detector. The detector is first optimized on labeled examples, improving from 80% to 100% on its cited 20-example evaluation set; it is then used as an LLM judge to optimize the humanizer, which rises from a 10% to roughly 70% ability to fool that judge. The point is not AI-detection specifically, but the reusable optimizer-evaluator pattern: when a task has subjective or expensive-to-label outputs, build a separately verifiable judge, validate the judge, and use it as the optimization metric for the primary task.

The strongest operational message is that evaluation data—not clever prompt text—is the compounding asset. Instead of accumulating one-line prompt patches such as “not like that,” teams should capture failure cases as labeled examples. Those examples can be rerun against new models, optimizers, and deployment versions, turning model migration into a measured decision on quality, latency, and cost. The speakers recommend inspecting data directly, maintaining train/test or holdout splits, and treating optimized programs as versioned artifacts that are compared before promotion.

The latter portion is especially relevant to agent systems. Recursive Language Models (RLMs) give an LLM a Python/REPL-style environment in which it can decompose large jobs, call subagents, manipulate intermediate artifacts with code, and avoid brittle serial or parallel native tool-call generation. DSPy Flex generalizes this: an optimizer can search over task decompositions and inference strategies—such as RLM plus reusable tools, deterministic code heuristics, and LLM fallbacks—while preserving the same signature-level interface. This is a credible pattern for compiling flexible exploratory agent behavior into more deterministic, evaluable production workflows.

Key Takeaways

  • Claim: DSPy’s core abstraction is a stable, typed task specification, while prompts, models, provider syntax, and inference strategies are replaceable implementation details. | Evidence: The walkthrough defines signatures as a task docstring plus explicit DSPy input and output fields; the same program can switch models by changing the configured model string. Drew says programs written two years earlier still work after model swaps and re-optimization. | Implication: Define agent skills and AI workflows around explicit contracts—inputs, outputs, and success criteria—rather than provider-specific prompt files, so model routing and upgrades do not require rewriting the application. | Caveat: A signature is only as good as the task definition; DSPy cannot resolve ambiguity about what outcome the team actually wants.
  • Claim: Structured outputs are a major operational advantage because they remove fragile parsing and make LLM stages composable in code. | Evidence: The speakers show DSPy returning a named human_text field directly rather than requiring regex extraction or prompt conventions such as “respond with valid JSON.” They cite passing a large Pydantic schema for Overture Maps geospatial data and using a complex Pydantic survey object across 5,000 generated personas without fallback parsing logic. | Implication: Use typed output schemas at every agent boundary where downstream code, tools, or other agents depend on reliable fields; avoid making parsers a hidden part of the system’s reliability model.
  • Claim: For subjective tasks, optimize a validated judge first, then use that judge to optimize the generation task—the optimizer-evaluator pattern. | Evidence: In the demo, a labeled AI-vs-human classifier starts at 80% accuracy and is optimized to 20/20 correct examples; that judge then evaluates humanized text, enabling the humanizer to improve from a 10% to about 70% judge-passing rate. | Implication: For meeting briefs, research prioritization, sales copy, agent-quality scoring, or other hard-to-specify tasks, build an independently testable proxy evaluator before allowing automated prompt or workflow optimization. | Caveat: A generator trained against a single judge can learn to exploit that judge rather than satisfy the real-world objective; the cited 100% result is on a very small 20-example set, so holdouts, human review, and/or multiple judges are needed before treating it as production-grade.
  • Claim: Evaluation examples are durable capital, whereas ad hoc prompt patches are model-specific technical debt. | Evidence: The speakers contrast repeated prompt hot fixes—“not like that”—with saving each failure as a concrete labeled “not like this” example. They recommend train/test splits, optional untouched final holdouts, direct data inspection, and even lightweight custom visual interfaces such as Tinder-style data review. | Implication: Create a failure-capture loop for every production agent: turn incidents, operator corrections, and edge cases into labeled eval records that can gate future model, prompt, tool, and workflow changes. | Caveat: More examples are not automatically better; sample needs depend on task diversity and exactness. They cite roughly 20 examples as enough to begin, around 50 as a practical sweet spot, and 100–200 for some exact matching tasks.
  • Claim: DSPy optimizers can outperform one-shot prompt generation because they iteratively test prompt variants against feedback rather than merely proposing plausible instructions. | Evidence: The demo uses GEPA, described as a genetic/Pareto-front optimizer, with a stronger model to inspect failures and propose revisions. The cited run takes about 15 minutes and approximately $1, moving the classifier from 80% to 100% on its evaluation set. The speakers say GEPA carries winning variants forward while exploring mutations. | Implication: Treat prompt optimization as a budgeted experiment with explicit score, latency, and cost outputs—not as an untracked conversational iteration process. | Caveat: Optimization performance depends on the representativeness and integrity of the metric and data; a stronger optimizer only accelerates movement toward the metric, including a bad metric.
  • Claim: RLMs are a useful default inference strategy for long-context, code-manipulation, and high-fan-out tool-use tasks; DSPy Flex extends this toward automated workflow synthesis. | Evidence: Isaac describes an RLM as giving the model inputs as variables in a Python REPL, allowing it to write code, dispatch subagents to summarize individual book chapters, combine results in loops, and avoid generating many native tool calls. Flex then searches combinations of RLMs, tools, heuristics, decompositions, and LLM fallbacks under one signature. | Implication: For OpenClaw-style systems, start with an evaluable flexible agent for complex tasks, mine its repeated behaviors into explicit tools or deterministic functions, and retain the flexible path as a fallback where it demonstrably improves outcomes. | Caveat: The described Flex capabilities and metric-learning work are presented as active or forthcoming research/product work, not as a fully characterized production guarantee.
  • Claim: Model selection should be continuously evaluated as a quality-cost-reliability decision, not made by vendor preference or general benchmark reputation. | Evidence: After optimization, the demo swaps in Gemini with minimal code changes and reports an increase from roughly 75% to 85%; the speakers frame the next decision as whether the extra reliability is worth the added spend. They compare reusable eval suites to literal currency because every new model can be tested against them. | Implication: Maintain a model-routing benchmark per workflow and establish promotion thresholds that combine task quality, inference cost, latency, and operational failure rates.

Detailed Brief

Implementation primitives and deployment lifecycle

  • Claims: A DSPy module is broader than a prompt template: it can combine LLM calls with deterministic validation or acceptance code.; The speakers say many workflows can begin with simple Predict modules chained together, adding strategies such as Chain-of-Thought only when measurement supports it.; Compound is building platform infrastructure around deployed DSPy programs: state management, execution visibility, optimization-created versions, comparison testing, and promotion decisions.
  • Evidence: A cited example is validating whether generated SQL is valid for a particular database after an LLM stage.; The discussion notes that DSPy recently moved away from LiteLLM, with the maintainers characterizing the resulting dependency footprint as slimmer.; They describe production use of “best-of-N”: generate multiple outputs, score them with the trained judge, and return the best-scoring candidate.
  • Caveats: Best-of-N improves only according to the deployed evaluator and increases inference expenditure; it should be used where its incremental quality is worth the added latency and spend.; Prompt internals remain inspectable, but the speakers warn that spending excessive effort manually prompt-engineering signature docstrings is a signal that the team may be bypassing the value of the optimizer/eval loop.
  • Implications: A production control plane should version the full executable program, its evaluator, model configuration, and dataset—not only prompt text.; Use acceptance-code checks alongside LLM judges for non-negotiable requirements such as schema validity, permissions, data integrity, or policy constraints.

Context management and agent failure monitoring

  • Claims: Long-running optimization and research agents can become context-inert: as context grows, they may overcommit to a local solution and stop making substantive edits.; Strategic forgetting—called “fork and flush” or context flushing in related work—can restore exploration by resetting context rather than continually extending it.; DSPy decision models can classify agent failure modes and be compiled into another implementation format for deployment.
  • Evidence: The speakers reference ShengYen Tan’s work, which they summarize as finding shorter reasoning traces and progressively smaller edits as context length grows.; Drew describes using a DSPy decision-model program trained on Melissa Pan’s MAST agent-failure taxonomy to detect looping, task drift, and related failures in coding agents, then translating the optimized logic into TypeScript.
  • Caveats: The referenced papers and reported observations are discussed informally; the video does not provide experimental details sufficient to determine where reset policies outperform persistent context for a particular production workload.
  • Implications: Instrument agents for loop/drift detection and create explicit reset, branch, or replan policies rather than assuming more accumulated context always improves performance.; Use a framework like DSPy as a compiler/testbed for classifier logic, even if the production runtime uses a different language or lower-latency decision-model implementation.

Notable Concepts & Terms

  • DSPy Signature: The durable specification of a task: a natural-language task description plus typed, named inputs and outputs. It decouples what the system must do from how a current model is prompted to do it.
  • DSPy Module: A composable execution unit that can include an LLM prediction strategy, deterministic code, validation, and multi-stage control flow—not merely a prompt.
  • Optimizer-evaluator pattern: Train or validate a judge on an objective, labeled task, then use the judge as the optimization signal for a subjective generation task.
  • GEPA: The optimizer featured in the walkthrough. It uses model-generated prompt improvements and iterative evaluation, preserving promising candidates while exploring variations in a genetic/Pareto-style search.
  • RLM (Recursive Language Model): An inference strategy in which an LLM works through a code/REPL environment, can manipulate inputs programmatically, and can delegate portions of a task to subagents.
  • DSPy Flex: A described approach in which optimization searches over broader implementation choices—decomposition, RLM behavior, tools, heuristics, and fallbacks—while maintaining the same signature-level task contract.
  • Context inertia / fork and flush: The claim that long-lived model context can lead to fixation and shrinking edits; deliberate context resets or branches can restore exploratory behavior.
  • MAST: Melissa Pan’s cited taxonomy/training data for agent failure modes, used in the discussion as a basis for detecting issues such as looping and task drift.

Operator Notes / Why Ken Should Care

  • Select one high-value OpenClaw skill with measurable outputs—such as meeting-debrief extraction, research triage, tool-call selection, or workflow QA—and express it as a typed input/output contract before touching the prompt.
  • Stand up an eval repository with: production examples, corrected failures, a train/test split, an untouched promotion holdout, and metadata for model, cost, latency, and tool outcomes.
  • Do not use an LLM judge as the sole production truth source. Pair it with deterministic checks where possible, periodic human calibration, and adversarial/holdout examples to detect reward hacking.
  • Add a deployment gate that compares incumbent versus candidate model/program versions on quality, p95 latency, token cost, and safety/format failure rate; promote only when the tradeoff meets an explicit threshold.
  • For long-context agent jobs, prototype an RLM-style decomposition and log repeated generated code/tool patterns; convert stable repeats into first-class tools or deterministic subroutines.
  • Implement agent-health classifiers for looping, drift, repeated tool errors, and stalled plans, then define whether each signal should trigger retry, context flush, replan, model escalation, or human review.

Source/Metadata

  • Title: Context Engineering With DSPy
  • Transcript words: 18466
  • Duration seconds: 4169
  • Timestamp note: No usable timestamps or chapter markers were present in the supplied transcript; the transcript also contains substantial duplicated segments near the end.

Transcript

11945 words en Processed in 394.5s

All right, and we are live. All right, we're live. Hey, Drew. Hey, Isaac. How's it going? Good. How are you? I'm good. I'm good. Yeah, I've been doing a bunch of DSPy over the past few days, optimize my writing styles, so I'm very keen to talk about it. Do you think you could write rules for your writing style for me that would help me write like you? Or have you been discovering this as you've gone? Because you clearly have to do that for the AI, but could you do it for me? Oh, I'd prefer to write like you. Yeah, I mean, I've tried that before a bunch of times, and it doesn't work because just because there's a rule doesn't mean it's actually going to follow the rule, and that's why we need DSPy. What if you made a classifier that was trying to detect if the writing was even? Uh-oh. Oh, we lost Isaac. Lost Isaac. What's we can infer? Big writing has cut him off. Am I actually gone? No, you're back. You're back now. Okay. Yeah, no, I think that's a failure mode, which is the model doesn't listen. Which is a constant one. Everyone who has talked to me in the last month has heard me rant about Claude's design eyebrows. Those little all caps, tiny headlines they put on top of the separate headlines. Yeah. Which, I'm old enough to want to make a yo dog joke right there because that's what it is. Like I heard you like headlines. But you have to—it takes so much to get Claude not to do that. Like you really have to repeat it over and over and over again. But I think there's another failure mode, which is if you describe how you write and give it to me, I guarantee you, you are going to miss nuances that you're not aware of. Yeah. There are going to be things that you don't recognize that you yourself are doing that I won't have those instructions. And so I'm going to fail. And then it's going to be a game of telephone where we're going back and forth as you're trying to capture that. So I want to make sure we flag that one there. It's a pretty big failure mode. Yeah. You are not the best judge of your own stuff. Yeah. I call that the high school band problem. I used to play in bands a lot in high school, and when you're in a band in high school, people always come up to you and you're like, what's your band sound like? And you have such a hard time describing. You don't want to pin yourself down. You're like, we're totally unique. We're like this. And then they ask your friend and their friend's like, yeah, they're trying to play like Modest Mouse. And I'm like, okay. Oh, that's good. Well, we need to riff on this. We haven't covered this yet, but I was in a Rage Against the Machine cover band. So was I. Oh my God. We're the only two people. I have not. I'll admit I have them. We need to form one now. Cool. Well, let's get to the Rage Against the Machine stuff at the end. So let's introduce DSPy. Let's introduce ourselves and why we're here. So I'm Mike Taylor. I'm the head of evals at Every. I have been using DSPy for several years now. And the reason I started using it is because I was a prompt engineer. I went to the AI Engineer Conference, the first one in San Francisco, and someone came up to me and very confidently said, didn't you know that prompt engineering is dead already? And I'm like, what? What do you mean? And he's like, try DSPy. So that night I went home, tried DSPy, the thing that was going to put me out of business, which is ironic because, as a prompt engineer, that's what people accused me of. But we automated ourselves first and tried it. And I realized that all of the things around prompt engineering that made prompt engineering good, you still need to do those things with DSPy. But it took away one of the major problems with prompt engineering, which is that you don't have to write all these brittle text strings every time. And then a new model comes out and you go from GPT 3.5 to 4 at the time. And now it doesn't work. A lot of the rules that you wrote down, they just don't work anymore. The magic words that you found, they don't resonate with this new model. And so DSPy solved that problem for me, which is I can do all the fun stuff around the prompt, but I don't need to write the prompt anymore. And DSPy is really a container for helping me move that infrastructure around from model to model. Do you think I've captured it well, Drew, Isaac? And just for introduction's sake, Drew and Isaac are co-founders of Compound. I'll let you guys introduce what that is. Isaac's a lead maintainer on DSPy specifically. And Drew is the guy that got O'Reilly to commission my book. So I'm in debt to both of you guys. Yeah, no, definitely. They asked me if I think DSPy is still relevant. And I'm like, well, how much time do you have? I think one of the things that's most impressive about DSPy is how the interface has not really changed that much since it was first created pre-ChatGPT. Like they really nailed wanting to define your task with typed inputs and outputs. And the thing that's great about that—I really like DSPy is it's actually really good for illustrating context engineering concepts as code. Because it kind of reads like pseudocode. It's really easy to read. And I would much prefer to read a DSPy signature than I would a long markdown file or a triple quoted string. So it's not just something that allows you to define something that you can carry around. My DSPy programs I've written two years ago still work. I just keep changing the model, re-optimizing them. The task stays the same. The implementation changes. But they're also super easy to wrap your head around and read. Yeah. It's actually the only code that I read now. Yeah, no, exactly. And we were just building a skill. So Isaac and I at Compound. So not only are we the team behind DSPy, but we also work with enterprises who are using DSPy, like Dropbox, Shopify, Figma, and others. And the goal that we work on is we're pushing DSPy forward, continuing to modernize it behind the scenes. The signature stays the same, but there may be new inference time strategies. There may be new tooling. There may be different ways to prompt cache on the different providers. We may have decision models come out that, as TypeSafe says, is very DSPy pilled. Yeah. Like we want all of that to work seamlessly and easily and performantly. But we're also starting to build products where that work as infrastructure for DSPy, kind of manage your state where you can write a program, push it to the platform. You can call it there. You can see how it runs. You can optimize it. When it optimizes, it creates a new version of the program. You can test that version versus the old program, decide if you want to promote it. And that's what we're working towards. And in about the next four to six weeks, we'll have some stuff to share on that. Yeah, I strongly agree with that approach. The task definition stays the same. It's the implementation underneath that changes. And that's really impressive how consistent that interface has been as literally everything else within the AI ecosystem has continually been reinvented and changed. Yeah. Omar was kind of a visionary. Omar gets a lot of credit for that because signatures will never change because your tasks that you're solving, they evolve as you learn more about your tasks. But by definition, they don't care about the implementation underneath. Yeah. Yeah. Cool. So I want to get into a few different things with both of you guys. I think it might make sense to show some DSPy. I've got an example from the book that I worked on, DSPy in Eight Steps. This is an homage to the original DSPy documentation, if you guys remember that, which I really liked. But the new documentation is significantly better. I just loved how catchy the DSPy in Eight Steps thing was. But I think the new documentation is different. And I think this is also another challenge that we have, which is like, what is the role of documentation for humans these days versus for agents? Yeah. Omar was a visionary. Omar gets a lot of credit for that because signatures will never change because your tasks that you're solving, they evolve as you learn more about your tasks. But by definition, they don't care about the implementation underneath. Yeah. Yeah. Cool. So I want to get into a few different things with both of you guys. I think it might make sense. Maybe we just show some DSPy. I've got an example from the book that I worked on, DSPy in Eight Steps. This is an homage to the original DSPy documentation, if you guys look at that, which I really liked. But the new documentation is significantly better, but I just loved how catchy the DSPy in Eight Steps thing was. But I think the new documentation is different. And I think this is also another challenge that we have, which is, what is the role of documentation for humans these days versus for agents? And you need to just build mental models so people know what to ask for when they sit down at the keyboard so you don't have to go in as deep. Yeah, exactly. And so let me share my screen. I'm just going to bring this up. So you guys should. Yeah, you can see that. Cool. So we have a notebook here and you're looking at some DSPy, right? So there's a couple of things that stand out. First thing is we are using GPT 5.6 Lunar here. This is all you need to do to configure it. So, you know, we have DSPy.lm. I can zoom in a little bit so you guys can see it a little bit easier. We have, you know, a one-liner. It pulls my API key and then it does all the magic stuff under the hood to connect it to the format that OpenAI needs the API calls in. Right? So, you know, if you want to change that model, it's literally just, you know, let's just change this text string here. And then you have a different model that you can run. So I think that's one of the core things is that you're abstracting away a lot of the model infrastructure. And I'm sure that Isaac can talk to how much fun that is to keep maintained as everything's changing. As of yesterday, we are no longer on LightLM and DSPy, which is very exciting. And yeah, Herculean effort by Isaac and Max and team. Just really great stuff. That's great. So, yeah, for people who don't know, LightLM was handling a lot of that stuff for the DSPy guys. But they've just moved off that dependency now. So DSPy is a little bit slimmer than it used to be. And then you can configure it. So this is configuring the model globally. You can also call it directly as well. But, you know, that's all you need to get your LLM set up. Right? And then this is a signature. So this might not look like much. And actually what I came to DSPy for was the optimizers, which we'll get into. And that's the really powerful stuff. But I want to pause a little bit on the signature because people always say about DSPy, you come for the optimizers, you stay for the signatures. And it feels really true. This is now how I think about using LLMs because every time I'm purposely diving into micromanage a task with an AI, it's because that's part of a workflow. And so here we have a class inherits from DSPy signature. Inheriting from that means that it can understand how to compile that in a way that goes to OpenAI or to Google or to any of the other models. And then we have the doc string. I think about it as the starting point for the prompt. This might change. But this is where you're describing the task. This is the part that actually tripped me up a lot. And I think quite a few people hate. But I've come to put up with it and live with it. It feels unnatural to put your prompt in a doc string, especially if you're used to writing prompts by hand. So I would say if you feel weirded out by this, just bear with it because you do get used to it. I think the other thing, too, especially if you're working on an optimization pipeline, I kind of like—Isaac may cringe a little bit here. But if you're starting and you have a long documentation or whatever, it's okay to add it with the instructions parameter. And actually pretty long. I was just recently running a test where I had a very thin doc string and then I evaluated it and said, all right, how high did it get? How long did it take? And then I had a really rich doc string, almost like a skills worth of markdown that I was loading, describing my workflow. And I did the same thing. And for this specific task, it both required optimization. So the eval still weren't captured accurately in the skill and they added it. But after the optimization, it got to where it went to. So I kind of like, you know, there's no real wrong way to do this here. Yeah. But I really like doing it this way because it makes me think, okay, forget about all the big pages of text, right? What is the actual task that I'm trying to do here? I'm trying, in this case, I'm humanizing AI text, right? I'm trying to transform AI generated text into natural human-like writing. Yes. And so that is the task, right? And it's actually important step. The one thing I like about DSPy is it forces you to do your homework. It's, okay, what actually am I trying to do here? And it's not always obvious. And then you have the inputs and outputs, right? So this one is very simple. It just has one input, one output. It takes in some AI generated text. And you can just call it AI text. You don't have to give a description, but in this case I have. And then the output is the human text. And so you just put in DSPy input field, DSPy output field. And that's your signature, right? Because that is very easy to read. It's, here's my text. You know, here's what I'm trying to do. Here's the input. Here's the output. I find that DSPy is really good for scripting. And I build a lot of CLIs in DSPy for this reason. Because I'm, oh yeah, it's always, what's the input? What's the output? And then I actually don't have to write the prompt. I don't have to think about it. And so that's all DSPy really needs to start building the program. So yeah, anything you guys want to say at this point before we move on? I'm probably butchering it, Isaac. Someone who intimately knows this. Look, I think you're exactly right. I think the one trick with the doc string is that if you find yourself prompt engineering inside the doc string too much, then that's a big red flag. But certainly dump all your information in there and then learn more later. Yeah. Yeah. Cool. And then here's another signature, right? So we are generating, we are humanizing the AI generated text here. And then here, this is an AI detector. So same format, right? Except in this case, it's a different task. Detect whether text is AI generated. And then we're just taking in some text. We don't know if it's AI generated or not. And then we're just checking, is this AI? So this is super simple. You can obviously build a much more complex program than this. And you can join these things together as well. But hopefully you can see the patterns here. You always have inputs, outputs, and the doc string. And the words you use to describe these things also matter as well. Very cool. So what this program does is it takes in, so now we're getting into a module. A module is basically where you assemble your different parts. And so it's just a traditional Python class. You have your init function. In this case, it has this method humanize, right? And so what we're adding on top is this predict module. So this is the base module of, you know, you have a signature. You've defined your inputs and outputs. That's your spec. And then predict is what happens under the hood to generate the text, right? Or to generate the outputs from the inputs. So predict is the base level. They also have a bunch of other, and we'll show you this in a sec. There's a bunch of other, these baked-in custom modules that you can employ. And so if we wanted to, you know, make this chain of thought, if we just add that, it still has the predict underneath. A module is where you assemble your different parts. It's just like a traditional Python class. You have your init function. In this case, it has this method humanize, right? And so what we're adding on top is just this predict module. So this is the base module of you have a signature. You've defined your inputs and outputs. That's like your spec. And then predict is what happens under the hood to generate the text, right? Or to generate the outputs from the inputs. So predict is the base level. They also have a bunch of other, and we'll show you this in a sec. There's a bunch of other baked-in custom modules that you can employ. And so if we wanted to make this chain of thought, if we just add that, it still has the predict underneath. But this is just a way of adding a new prompt engineering strategy, right? We used to do this manually by saying think step by step and then answer this question, right? And that's what chain of thought is doing. There are a bunch of these, which we'll get into. But you can actually get 80% of the way with just predict. Yeah, and I think the thing that's important about modules is they're not just prompt engineering. There also could be code. So it's any test time strategy. So, for example, you could say put a prompt in to kind of contextualize your task, get the results, and then you could check it with code. Maybe you have a specific acceptance function to say, is this valid SQL given our database or what have you? And you've essentially built a test time strategy right there. And that's a good way to think about modules. Yeah, exactly. And you can get a lot more complicated with this. But you don't need to. I would say 80%, 90% of the time, all I'm doing is stringing together a bunch of predicts. And so we built our AI detector and we built our text transformer. We've got the two different parts of our program. And so we have everything we need to run our pipeline. We're going to try and humanize the text. We're going to take some AI generated text and try and make it sound more human. And then we're going to check whether it passes the AI detector. I'm very curious what this is going to be out of those. Yeah. So, first of all, you need some data, right? And I think this is the doing your homework part of DSPy. It's not magic, right? You can't really do anything unless you have some data, right? You can generate the data with DSPy as well, some synthetic data. But I would say most of my work post-DSPy in prompt engineering and AI engineering generally is just can I find some great examples? Or can I handwrite them myself? Can I work with a domain expert to find them? This is the boring but necessary part of doing the job today. Yeah. And I think what's really nice about this, especially if you're a product owner or someone building the AI engineering pipeline, often you're not the subject matter expert. And if you're working with the subject matter expert and you're building all of your logic into code and prompts, the problem is now your subject matter expert is essentially editing those things. And we talk to some enterprises where the subject matter experts are even really going deep. And now it becomes code conflicts and all these other things. It's the same thing here, which is we just want the subject matter expert to have their examples in their own little space where they can really write whatever they want. And it's isolated from your logic flow and control flow. Exactly. Yeah. And it feels like the transition. I remember at the time Carpathia was talking about self-driving. And he was like, we started off writing all these different rules, like when you see a sign that there's this shade of red, it's a stop sign or whatever, right? And then eventually it just became, hey, here's all the video of the last 400,000 miles. Put it in the machine and then stir, you know? Yeah. Or it's like you know, it flags it and you have to have the guy who's driving the car remotely drive around the construction site. That would be really hard to write the rules for, but it's really easy just to watch them go. Exactly. And so DSPy is doing that self-driving for you, but for your programs. So your job is to collect the footage. So here are some texts that were AI generated. And I specifically made sure that they had AI tells in them. And so what we're doing here is basically just taking the example. It's taking the text from the text. And then it's printing it out. And then it's humanizing it. All right. So we're using our humanizer here. So you can see here, response equals transformer. And then we're passing in the text, which is the one input that we need to pass in. So if we go back here, you can see with the humanizer, you know, the humanized AI text has just this one input AI text and then one output human text. And so when we put that in, that's when DSPy is taking the inputs, generating the response, giving you the output, and then passing it back. And so the interesting thing here is that because DSPy is built in a way to have structured inputs and outputs, it can only basically give you that specific response. And so that's another thing that is underrated, I think. It's hugely underrated. Someone came to me yesterday and they're like, hey, I need to write optimization so that my outputs are following the object format I define. And I'm like, you can use DSPy and you don't even have to write the optimizations for that. It's basically just defining the model or the base class and you're done. Exactly. So you can feel confident that there is a dot human text here, right? We didn't have to write any regex, right? We didn't have to write any parsing code. We didn't have to tell the model, hey, can you make sure you give the human response with a human response colon and then we'll snip the regex. None of that. It's all gone away. And you can take it really far. Why would an agent want to use DSPy when it can write everything itself? And that's because writing parsing code is a complete pain. And no one should have to write parsing code. Even your agent. Yeah. Well, my agents have to, but your agents shouldn't. Yeah, exactly. You can think of it like your agent has donated the tokens to our agents. It's done all that hard stuff for us. And I want to say how far you can take this. At the Overture Maps Foundation, which is a Linux foundation for free and open geospatial data, we use DSPy to prepare data for our pipelines. And we, for some of the tasks, if we're looking at a data set and we don't know what the shape of that data set is, we will pass it the entire giant schema for Overture. It is this big Pydantic schema as the output type. And it'll nail it. It's unbelievable. It's really effective. And it basically guarantees our output in a lot of ways. Yeah. I've done this with persona-generated surveys. You know, for a large credit card company, I generated 5,000 AI personas. And they all matched the demographics of the different people that were trying to buy. And what they wanted to do is test different credit card offers and see which one would they choose. But the survey that the client was passing me was a real mess. Here are 15 different options. And they all had different sub options, right? And so I just made that output object in Pydantic and then pass that in. And then it's 5,000. And I had written all this extra code of, hey, if it doesn't come back with this, then try again, blah, blah. Yeah. I've done this with persona-generated surveys. So, for a large credit card company, I generated 5,000 AI personas. And they all matched the demographics of the different people that were trying to buy. And what they wanted to do is test different credit card offers and see which one would they choose. But the survey that the client was passing me was a real mess. It's here are 15 different options. And they all had different sub options, right? And so I just made that output object in Pydantic and then pass that in. And then it's 5,000. And I had written all this extra code of hey, if it doesn't come back with this, then try again, blah, blah. And none of it was needed. It nailed everything in the first shot. It's such a hidden feature that is so appreciated. Yeah, cool. So if you're a fan of structured input and outputs, then DSPY is for you, right? And actually, you mentioned TypeSafe earlier. So I talked to their team there. And the first 10 minutes of the call was Diogo making fun of me. He's you're writing a book on DSPY. Come on, we've skipped the text output now. We're just doing structured outputs. Was he in his pink jacket as he was doing that? Yeah, he changes. Yeah, just several costume changes per. No, I'm joking. Yeah, it was. Yeah, so if you're a fan of that. Then, yeah, I think one of the cool things about TypeSafe is that it is skipping this passing step, right? It is just giving you the structured output, which makes it very useful for certain things. And that's baked into DSPY now as well, right? You can use those decision models straight away. Yeah, you can use the decision model straight away, provided, per Diego, they are things that are compatible with his float outputs. So, say you're mixing a string output along with your decision. Of course, that's not going to work. But if you have things that are compatible, like Booleans, choices, all those other things, they're compatible with decision models. And what's even better is they're also compatible with LMs. So, you can write the same signature for your decision model. You may find that it's not up to snuff for your task. And you just change your model string, and it just works. It's wonderful. There you go. I think one of the really interesting societal things is that everything you can do with TypeSafe, you could have done since 2022 in DSPY. But TypeSafe, for some reason, hit this philosophical inflection curve where everyone is like, oh, actually, if it's really fast and really cheap, then I will try and actually build things with it. And so, now it's caught fire, and people are really into building little AI functions. Yeah, the sign of a good model, we do a lot of vibe checks at every, right? We get early access to the models, and we keep coming back to this. The sign of a good model is it raises your level of ambition, and you start doing different tasks than you were doing before that you didn't consider trying. And so, you know, I've been making a lot of documentaries that were purely AI generated. So, now I don't hand in a HTML page or an email of here's the work I did. I use Opus to actually create a video of it interviews me, it does a documentary, which is really fun if you've seen it on my Twitter. But that came from we're testing another model that's not out yet, and it was oh, wow, it did this. And I'm oh, wait, I actually found that I could have done that all along in Opus. I just didn't think to try it. And, you know, TypeSafe, I think, is the same thing. It's I already was doing a lot of large-scale classification with Luna or, you know, GPT Mini before that. But, yeah, Jev basically made everyone think, oh, can I boil this down to a classification problem? And if so, now you can compare Luna to Jev directly in DSPY, which is nice. Yeah, very cool. Cool. So, you can see the outputs here. So, that's the text that went in, and then we humanized it. But, unfortunately, it still knows that it's AI, right? So, is AI true? Is AI true? Is AI true? So, we have a program that humanizes the text, but it doesn't work very well yet. But, first of all, it's amazing that we just had a couple of lines of code, and now we have this full program, and we can run that again with a different model and see if there's another model that's good at judging or another model that's good at generating or tricking the judge. Just what I always like to pause here for, my fellow prompt engineering bros. You can see the prompt if you want to, right? So, I'm inspecting here the history. And so, you can see the system message that DSPY wrote for you. And it might look a little bit weird. You can change this. This is this format. Isaac, I don't know if you know the history of why this format, or Drew, maybe you know. But I've only seen this format in DSPY. Or the chat format. Yeah, this is all, yeah. It was back when we were still doing demo optimization. The models weren't good enough at XML because it had more tags. And JSON was really hard to get all the tokens right. And so, this was the best thing we had back in 2022, 2023. But now that we're in 2026, XML is the default. Also, getting released in 3.5 in a few weeks. Yeah. Oh, it's becoming the default now? Yeah, that's big news. And not only that, it's the other thing that I think is important for people to know, getting to see the behind the scenes, is just the standard that Isaac holds these decisions to. So, we have DSPyBench. And it's a ton of evals that every decision, like, should we make XML the default, gets run against everything. And it's even if it has to be able to perform as well. There can be no performance hit. And we hit that level. And it's very good. Because a lot of people on the call may not realize, but Mike certainly does, is back in the days of prompt engineering, the white whale was getting consistent JSON output without markdown fences around it and text around it. And threats. Oh, my God. Yeah, Isaac has no fingers and he can't manually change this to valid JSON. So, you must output valid JSON. That does a literal prompt that I used to use. Now it's all solved. And I'd love my fingers back if you find it. Yeah, exactly. Cool. So, let's go through here. So, we've seen the prompt. You know, you can see all the user message, et cetera. But the whole point of DSPY is you don't have to worry about the prompt anymore. So, what we're going to do is load a lot more data. So, I have a CSV that's prepared. By the way, this is in the repo, which is open source for the book. So, even if you don't buy the book, you can take a look at this example and look at the data. But I basically prepared a lot of human-generated text and AI-generated text. And then I'm just going to load this into a data frame in pandas, right? So, the DSPY to work, it has a specific example format where you put in. And this is just a shorthand I use to load everything in. Basically, I'm just unbundling all the columns from the pandas data frame. And then putting it all in there. And then I'm just telling it what the inputs are. So, with inputs text for each example in the examples data frame. So, that's how we're getting our data set. And then we're, you know, good ML AI people, we're doing a train test split. By the way, this is in the repo, which is open source for the book. So, even if you don't buy the book, you can take a look at this example and look at the data. But I prepared a lot of human-generated text and AI-generated text. And then I'm just going to load this into a data frame in pandas, right? So, the DSPy to work, it has a specific example format where you put in. And this is just a shorthand I use to load everything in. I'm just unbundling all the columns from the pandas data frame. And then putting it all in there. And then I'm just telling it what the inputs are. So, with inputs text for each example in the examples data frame. So, that's how we're getting our data set. And then we're doing a train test split. So, the reason, if you're not familiar with this stuff, the reason why we need to do this is we need to see whether this actually works, is going to work in the real world, right? And so, it could very easily just memorize the answer to every test. And then when you get out there in the real world, it doesn't work when you show it a new example. So, that's part of the reason. And you can obviously go much further with this as well. You can have an extra holdout that, if you're very paranoid about this not working, you can have another holdout that you didn't even use in DSPy. And then run a final test at the end as well. But this is a small data set. And then we just need an eval metric. And I say just need because evals is my whole job, right? It's a very, very hard thing to do. And AI still isn't that great at making evals. But in this case, at least it's easy because our examples are providing the answers. For each example in the data set, we have a column which is whether it actually is AI or not because I made that data set, right? So, this is the ideal case: there is a correct answer. But obviously, you can get into it. We're going to show you how to score more subjective things later on in this worksheet. So, in this case, it just basically returns the score of one if it correctly guesses whether it was AI or not. The other thing to note here is that I have some notes in the data set. So, basically, what it would do is I've explained why this is an AI tell in that data set. So, for optimization, we're also giving it feedback as to why it got something wrong as well. And that's optional, but it does help. Cool. All right. So, let me just jump in. So, what we're doing here is we're creating an LLM judge. So, what we want to do is we want to train our humanizer, right? And our humanizer is taking in some text and then it's rewriting it as human text. But it's very hard to eval that, right? It's did it do a good job or not? It's pretty hard. I'm not going to manually test it hundreds of times or thousands of times. I'm not going to manually go and judge each one of those. So, one of the tricks I like to do in DSPy and the point of this workbook is it's called an optimizer evaluator pattern. I like to, if I have a subjective test, hey, does this rewritten text look like AI? I will first use DSPy to train the judge and then I'll use the judge to train the task. So, what we're doing here is the judge: for the judge, we can tell whether it judged correctly, right? If the judge, we know for the text that we have, we know that the judge either got it right or got it wrong because we've already marked down. But once the judge agrees with us and it's good at telling the difference between AI and human text, then we can use that judge as our proxy when we're training the other task, right? So, I'm just going to run this through. So, you should see this here. Yeah, here we go. So, this kind of shows you what we're doing, right? So, we have, here's the example. Here's the text, right? It was written, it was humanized by the humanizer. And then it got true as the score, right? So, if we look here, the score is the result score and that comes from the LLM judge. So, it's basically saying, is this judge just human? And the judge thinks this is human, right? And it's given its reasoning. The reason it gave its reasoning is, if we go way back here, we can see we used a chain of thought. By the way, did we fix the Sonnet 5.5 chain of thought issues yet? Oh, that's a big one. So, the problem with chain of thought that we ran into is chain of thought asks the model to share its reasoning. Which, for a long time, was completely fine. And that would actually, priming it to accept its reasoning was chain of thought is a method that dates back before reasoning models, before 01. But now, how far we've come, in the terms of service for Anthropic's models, starting with Claude, then eventually Opus, they are so worried about people training off them that they hide the reasoning. And they specifically say you cannot ask for the reasoning. And this is a guardrail akin to biohacking or security engineering. And so, in Sonnet 5.5 and Opus 5.5, they got much firmer guardrails and they would fail. And can it be used with Bedrock? Yes, it can. We do it every day, every time we hit a deploy. So, Isaac, you want to say how it works with Bedrock? Yeah. So, what happens is that it gets routed via the library we're using, which is LM15. And so, if you put in a Bedrock-based model and you're using API key-based authentication, then it will work natively. Or if you're using an authenticated client, then I'll link you an example that shows you how to do that. Yeah. And also, at times, the AWS and Bedrock team have used DSPy, especially from migrating people from one model to another using optimization. Yeah. And preempting the question, it also works with all the others as well, right? Yeah, basically. Yeah. Cool. So, what we're doing here, so we're evaluating our judge. And this evaluate function is basically a convenience method for you're passing your dataset, you pass in your metric, in this case, the exact match, but checking whether it judged the text as AI if it was AI. And then you can also change the number of threads. So, this is going to evaluate four at a time, right? And then it's going to display the progress and display a table at the end. So, this is just a way to basically establish a baseline. And so, what we can see is, all right, here's our text. This is the ground truth, right? The gold answer. So, this text is not AI. I wrote this. This one is AI. ChatGPT wrote this, right? And then we can see here the reasoning. It's reasoning through, trying to think about, hey, why would this be AI? Why would it not be AI? And then it's prediction, right? So, in this case, this wasn't AI, but it predicted it was true, so it got a score of zero. Whereas this one actually was AI and it was predicted true, so it got a score of one. So, I find it really, really helpful just to kind of see that view and scroll through and see which examples did it get wrong. Always look at your data, by the way, that's a fundamental thing. Every single time I run into issues, it's because I looked at the data and, okay, the data was wrong. Or this example is wrong. Or I can see why it's getting this wrong. And you can kind of make a change to your pipeline. Yeah. I encourage people who don't look at the data, which I know you and I are just scrolling through CSVs or what have you. But this is what vibe coding is for. Whip up an HTML page to visualize your data in whichever way you want. Yesterday, I did a Tinder-style swipe left and swipe right of my data. Always look at your data, by the way. That's fundamental. Every single time I run into issues, it's because I looked at the data and, okay, the data was wrong. Or this example is wrong. Or I can see why it's getting this wrong. And you can make a change to your pipeline. I encourage people who don't look at the data. I know you and I are scrolling through CSVs or what have you. But this is what vibe coding is for. Whip up an HTML page to visualize your data in whichever way you want. Yesterday, I did a Tinder-style swipe left and swipe right of my data. And it works great. You can just have fun with it. That's a great place to do it. And I encourage people to use it. Find some creativity in looking at your data to make it a little bit more entertaining. Exactly. You don't need to look at the code anymore, but you do need to look at your data. Cool. So you can see here that we got a score of 80%. What does that mean? It means we know the real answer of whether that was AI or not. The judge has tried to guess, and it's gotten 80% correct, right? So it's already a pretty good judge straight out of the box, which is nice. And this is with no optimization. And then we're evaluating our task. Running the same thing, evaluate. Except in this case, we're passing it instead of the exact match because we know the answer for the judge. We don't know the answer for the human, right? It's writing this text for the first time. It's not in our data set yet. And so we need a more subjective eval. And so we're taking the judge, which is 80% correct, and then we're using it to test this new text that the task model generated, right? I'm trying to see if it can trick the judge. And you can see here that the score is only 10%. That means it only tricked the judge 10% of the time. It generates some text. It tries to make it sound human, and the judge sees right through it. It can only get it right 10% of the time. So we have a pretty good judge, but we have a pretty bad humanizer right now. And this is where we've done all the boring stuff, all the homework. We're ready to go. This is where DSPy flies off the rails. This is what the crowd is here for. It's to optimize your program. This is how you get paid using DSPy. DSPy has a lot of optimizers here that we can use out of the box. I would say you can't really go wrong with JEPA. I still never know the right way to say that. JEPA. JEPA, okay, yeah. You can know because it conflicts with Yann LeCun's JEPA, J-E-P-A. And on brand, Yann at one point did go to a talk that Lakshya, who is the creator of JEPA, was giving about JEPA. And he went purely because he was annoyed that someone already had a name that was a homonym for what he had created. And his comment, he tweeted about it and said, told Lakshya he should change how it's pronounced to Jepa. This is the new Jif, Gif thing, right? Yeah. But purely for Yann LeCun to make sure he has clean namespace here. If you've upset Yann LeCun, it means you're doing a good job in AI or anything. So we're going to get AI to optimize AI here, right? And this was, I think, one of the other key insights is that very early on, even GPT-4 era, we realized that if you point it in the right way, these models are already human-level prompt engineers. And I would say they're probably past that now. Above average versus the average human prompt engineering. But they're way more persistent, right? They can try a lot more things than you or I would ever do. So the first thing you need to do is create another model here. This is a smarter LLM. I'm using Sonnet here. And we're going to use this model to rewrite the prompt, right? It's going to look at the failures and make changes to the prompt, and then it's going to run it again. It's not going to do the task, but it's going to teach the model that's doing the task how to do a better job. So you can think about it that way. You pass in all of the failures or what comes out of Llama, and it's effectively asking Sonnet, hey, how would you change the job? How would you prompt this model better to get the ideal response? We don't have time to run it. It takes about 15 minutes. It costs me about a dollar in OpenAI credits. But that's great because what we're doing here is we're training the judge, right? Our judge was already pretty good at 80%. We're going to see if we do a better job. And we passed in the AI detector. We passed in the training data and the way it can validate. This is the holdout. The important thing is we've given it that smart LLM to rewrite the prompt. It's going to look, see whether it got the prediction right or not, and then rewrite the prompt. This is what it looks like when it's optimizing. It's quite fun to watch if you haven't yet. You can see here's an example where it's proposed a new prompt here, iteration three. And this is how it's changing the prompt. It's coming up with its own rules. You don't have to write this, which is amazing and radicalizing where you see it. And it's going to keep going. It's going to score. And eventually it's going to get to the point where you see how well it's done. You can see we actually got in this case, 20 of 20 examples correct. So we went from 80% up to 100%. And what's funny is each model has its own weird nuances sometimes. There was a person who I remember maybe a year ago was running a bunch of evals on JEPA runs on GPT 3.5 20B. The small, super fast model. And they would look at the prompts that they arrived at. And for some reason, and there was a bunch of different tests, but all of the winning prompts ended with good luck. Which I just love. It's these weird ablations or weird things baked into the model. Yeah. And that's the thing. You don't have to care about what weird thing works for that model. We can rerun this again and get to 100% with a different judge or a cheaper model next time. And it might require more hand-holding or less hand-holding. We can save our program. Always good to do that once you have run it so you don't waste that dollar in spend. But then you can use that. So you can see it's got 100% here. You can use that to now optimize the original task. I'm going to speed through here. You can look at the prompt if you like, and you can see it's learned a few of these rules. Like, do not classify text as error generated merely because it's grammatical, generic, brief, or summarizes an idea. So it's figured out what actually works. And you can be really confident in these instructions. It's going to be much better than if you just ask Claude to write this, because it's proven that these rules have earned their place. If it added a rule that didn't work, it would have taken it back out. Yeah. And there's something else that's really important about this. And this applies to a question that Mike, you were asking me earlier for this call is, what's the difference between, say, JEPA handing it to Claude or even AutoResearch or similar things? Or even the meta harness paper? Yeah. You can look at the prompt if you like, and you can see it's learned a few of these rules. Do not classify text as error generated merely because it's grammatical, generic, brief, or summarizes an idea. So it figured out what actually works, right? And so you can be really confident in these instructions. It's going to be much better than if you just ask Claude to write this, right? Because it's proven that these rules have earned their place, right? If it added a rule that didn't work, it would have taken it back out. Yeah. And there's something else that's really important about this. And this applies to a question that Mike was asking me earlier for this call: what's the difference between, say, JEPA handing it to Claude or even auto research or similar things? Or even the meta harness paper? Yeah. And I think what's really important about this is that JEPA tends to win both in cost and the ceiling at what it can deliver because of how it manages the context and how it tests these things. So if it comes up with a winning prompt, it then uses that as the starting point to try out different variations and then test those in a genetic Pareto front. Hence, that's what JEPA stands for. And that additional structure turns out to bump the model out of distribution to find novel ideas. Yeah. Another researcher who works with Lakshia at UC Berkeley, Sheng Yen Tan, wrote a paper a couple weeks ago about how important forgetting is, especially in auto research, which is auto research. So the fork and flush thing? It's related to fork and flush. So I wrote this up on my blog as context inertia. So it covered Anthropic's paper that touched on it, fork and flush, and Sheng Yen's paper about forgetting. And they all came to the same conclusion, which is for long horizon tasks or optimizations, at some point, the model hyper focuses on a solution and it ignores better solutions that might require some lateral thinking. And the way to get out of this is you just delete the context. So fork and flush called it flushing. Sheng Yen called it forgetting. What I loved about Sheng Yen's paper is it talked about how he showed that the longer your context got, the less the model thought. The reasoning tokens were shorter as it went on. And the size of the edits, which to me is the biggest issue, got shorter and shorter and shorter and shorter. And if you forget, delete the context, it kind of resets it and bumps it back up. It's incredible. This also works for humans as well, by the way. Oh, yeah. A hundred percent. I will go. We'll go get some mushrooms. Maybe some alcohol. Just. I prefer a bonk on the head. Yeah, that too. Yeah. And actually, I'd like to see you go head to head with Jeff. Yeah. Yeah. Cool. All right. So I want to save some time for questions. So I just want to show you what we can then do, right? We're passing that trained judge. The one that now is a superstar. It gets a hundred percent. And it a hundred percent agrees with me on this specific data set, right? And you're not always going to get to a hundred percent. But I'm fairly confident now in this judge and I can use it to optimize my task. So when someone asks you, how do I optimize something that I don't know the right answer to? The answer is you find something else. You build a data set to train your judge. And then once you have a judge that you like, you can use it to train the original task. So here it's the same setup. And you can hopefully it's getting boring in a good way now. You're passing it to JEPA. You're passing in your metric. In this case, it's the optimized LLM judge and not the original one. And then you're passing in the smart LLM still because in this case, you want this LLM to rewrite the task prompt now. And, you know, lo and behold, we go through. We run, run, run, run, run, run, run. And bear in mind, this judge was not being tricked at all before this. And then we get to this prompt that it's written for us, which I'm not going to go into. But here we go. Now we're getting a 70%, right? So we took that mutated, evolutionary apex judge that JEPA found for us. And we've managed to now give the same treatment to the original task. So now the task, the task that humanizes the text, tries to trick the judge, try to make it sound like human text, has scored a 70%. So it's not tricking the judge every time, but it's gotten a lot better at tricking the judge. And you can keep going back and forth with this. This is the exact process that I used to create AI personas that sounded like real people, you know, with Ask Rally. And I've used this optimizer evaluator pattern on basically every project I've worked on. Yeah, no, it's incredible. And I think the other thing is that that's one of the things that's so nice about once you learn the primitives in DSPy. Is it applies to every project? And it helps you get up really quickly. One of the things that we want to work on is a general DSPy bootstrapping skill to adopt it. Because there's so many, just having your code being laid out this way is super handy. In fact, I even use it. So I have a Py plugin for the coding agent that uses a decision model to detect different failure modes that smaller models might get caught in. And so, looping or drifting off the task or other things like that. And so one of the other researchers at UC Berkeley we work with, Melissa Pan, has a training set that's she calls it MAST, measuring, I forget. It's agent failure taxonomies. And she has a training set of these things. And I built the DSPy decision model program to say, hey, is this training, is this failure mode being hit and using it to detect it? And I optimized everything, figured out all of the cuts, the right questions to ask with, ask the decision model. And then I output that program and then just had my coding agent rewrite that for me and type save. So I kind of had my compiler over here. And then I would ship it over here. And what that enables me to do is if Melissa makes new training data or I have new training data, I still can recompile it over here and then reship it and translate it. Yeah, that's great. And you can obviously, I'll share this. You can read this. I went on a little bit further. Started showing off. One of the fun things you can do is you can just, you know, it's all in DSPy, right? So you can just do this. This is called best event. You can run it multiple times and then just take the best one, right? So which one tricks the judge the most, right? This is, I think, the connection that a lot of people live in DSPy and Jupyter Notebooks. One of the things I think is underrated is taking the evals that you've trained and then putting them in production. Because if you have a text humanizer tool that you're putting out there, why not just rewrite the text 10 times and then use your DSPy judge to see which one is the best one? Yeah, I'm currently dogfooding something for us. Isaac correctly bothered me about it yesterday. So, Isaac, I went through my Hermes agent and I have some skills and cron jobs. And so I'm now starting to run my meeting debriefs. So it takes my transcript and then it outputs, you know, who was there, what are the decisions to be made. And then the other one is I have another one that reads the minutes of my local city council and tells me if there's anything to pay attention to. And that's actually a really hard eval because some things appear really boring, but I care about them. And so both of these things are getting DSPied and then we're going to be hosting them and then I'll continue to feed back at them and they're just tools. So, yeah. Yeah, great. And one last thing here is just to show you how easy it is. You know, we were working on this model. We got 75% now. The best event improved a little bit. And then we can drop in Gemini. We can say, hey, a new Gemini model came out. This isn't a new model. This is an older one. But, you know, you could say, you know, you want to try Argon on this, right? Is this a really good detector? And that's actually a really hard eval because some things appear really boring, but I care about them. And so both of these things are getting DSPied and then we're going to be hosting them and then I'll continue to feed back at them and they're just tools. Yeah, great. And one last thing here is just to show you how easy it is. We were working on this model. We got 75% now. The best event improved a little bit. And then we can drop in Gemini. We can say, hey, a new Gemini model came out. This isn't a new model. This is an older one. But you could say you want to try Argon on this, right? Is this a really good detector? You can now just do that, right? And then you can see here that we then bumped it up to 85%. So now you have to decide, hey, is it worth it for the extra money? How reliable does it need to be before it ships to production? And you can make those tradeoffs with your manager. I started my work in performance marketing or you run Facebook ads and you have to make $2 for every dollar you spend, right? And I feel like DSPy is one of those things that can help you do that in AI as well and show the ROI of the task, which is something that is escaping most people right now. Yeah. And I think that's one of the things that I think is, as you adopt DSPy, and I know, Mike, you feel this, which is, as you build your eval, that is gold. And when I say gold, I mean literal currency. You can run that against everything. And it's continually, new model, new whatever. You just keep running it. Yeah. I mean, obviously, I just wrote a book on this, so I'm pretty biased. If you want to check this out, I tried not to make it too much of a sales pitch for my book, more for DSPy, the open source library. But it is live on O'Reilly right now. It is on Amazon. I made this book specifically because I looked at the DSPy website originally, and I thought, I am too dumb to use this tool. And I still think I'm one of the dumbest people that uses DSPy. The documentation used to be really hard. Yeah. It's very academic, right? Like, it was made out of Stanford, MIT, et cetera. So I feel like me asking a lot of dumb questions has maybe helped evolve the library over time. But I realized that not everyone has that persistence. And honestly, DSPy paid me back with this, right? It's amazing. I was freelancing. You realize how easy it is to freelance when you're like, hey, I tried a new thing. This new model performs 50% better. Thank you very much. Right? It's pretty great thing to say to a client. And so if you can define the value and DSPy forces you to do that, then you can really show that return. And I think that's the key here. And hopefully more people get into DSPy. I have this conspiracy theory that everyone's using DSPy, but nobody's really talking about it because it's too good to share, you know? Yeah. Look, I've heard that a number of times of companies thinking it's their secret sauce. And so they won't talk about it. Yeah. They will say it to us because we'll reach out and we'll say, how are you using that? And then they'll say we aren't maintaining it. And it's a little cloak and dagger you have to go through. By the way, I will turn this into a sales pitch for your book because this book is excellent. I have read through it. And if anyone is interested in this, the other thing that's great about it is, first off, I want you to use DSPy. And I think this is the best way for you to get started with DSPy. But even if you bounce off DSPy, and if you do, let us know because I want to understand so that we can build the best library for whatever use case it is. But even if it's not your use case, everything in here is the way to understand context engineering as a structure and practice and can translate to any harness or framework you start building in. And it's pretty powerful. I think any team that ends up adopting the best eval practices just ends up building DSPy. And so Mike's book teaches you the best practices to just use DSPy from the start so that you don't have to run into roadblocks and then get there. Yeah. I had kind of built DSPy in Langchain at the time. And I was like, I had a really shitty offer. And then I was like, oh, okay. Yeah, I get it. Yeah. There's a great question about can non-technical users try this out if I'm only working at the Claude Code projects level? I think 100%. And I think the thing that is great about it, as we kind of said earlier, is if you're not a technical coder and you aren't used to reading code, the language that your model might come up with to structure your task might be really hard. But if you say, hey, use DSPy to build this, you're going to get code you can actually read and edit, which is because it's just well structured to be read and understood by humans. So yeah, I think. And the other thing that's great about DSPy, having the interface essentially having not changed since pre-ChatGPT, is that it's deeply in the weights. There's a couple failure modes that it will figure out, when it hooks up to the model, it'll put in temperature or other things that may not work. But your agent will figure that out. But it knows how to write signature and it knows how to do all of the other stuff. So, strongly recommend. And then yeah, big, strong yes. Great. So yeah, I don't know if you guys have a few more minutes maybe for questions you want to hang on. Definitely. I'm happy to do it. Because this question is one we get a lot, which is how many samples do you need to optimize? Yeah. Well, in that example there, I try and optimize with as few examples as possible. I find that even just one turn with Jepa, right, it's a better prompt than I was going to write, but yeah, in that example I had, I think it was 20 examples. So it's not a huge amount to get started. It's probably going to be what you would have done manually and it will do it faster. But I would say the real sweet spot is when you get north of around 50. Would you say that was similar? Yeah, I think it depends on the task. Like if you're doing something that you're trying to match exact data to one another, you might want 100, 200. That might be the answer that Lakshia and team will say. But also keep in mind, Lakshia built Jepa originally to improve an agent's ability to use documentation for, I think it was a Qualcomm instruction set for some sort of hardware chip. And he had around 40 examples in that original one. So I do think less examples is fine. But the other thing is, this is kind of the corollary of vibe coding to look at your data. The other thing you can do, too, is I have definitely said, hey, this is a failure mode I'm seeing. Can you synthesize some inputs that might evoke this failure mode that I can label? And that works really, really well, too. The thing that I want people to take away when building their eval data is that if you have a prompt and you're iterating in your prompt to build your system, you're going to add these one-liners, these little hot fixes saying, not like that, not like that, not like that. And then when you change to a model, you're going to have to go through each of those individually. If you spend a little bit more effort instead of saying, not like that in a markdown file, but instead say, not like this with an example, that is going to last forever. It is going to be a piece of value that you carry forward with this program definition throughout its life. So I really encourage you to invest that time. Yeah, that's, I'm going to steal that. I love that example of why example is great. And that works really, really well, too. The thing that I want people to take away when building their eval data is that if you have a prompt and you're iterating in your prompt to build your system, you're going to add these one-liners, these little hot fixes saying, not like that, not like that, not like that. And then when you change to a model, you're going to have to go through each of those individually. If you spend a little bit more effort instead of saying, not like that in a markdown file, but instead say, not like this with an example, that is going to last forever. It is going to be a piece of value that you carry forward with this program definition throughout its life. So I really encourage you to invest that time. Yeah, that's, I'm going to steal that. I love that example of why example is great. I wanted to, Isaac, I wanted to hear you speak a little bit about RLMs, if you have the time, and flex, and then kind of join that into like, what's the future of DSPy? Because I think maybe another underrated thing people don't realize is that DSPy seems to be either ahead of the curve or very much on top of the curve with Jeff for these new innovations coming out. Do you want to just explain, first of all, maybe RLMs and then flex, because I think they're kind of related topics? Yeah. So RLMs are an inference time strategy that's very flexible. It basically is the equivalent of code mode for an LLM, where you give it all of the variables and your inputs in its context as variables inside of a Python REPL, and you say, hey, write code in order to do this signature. So if you have a book and you want to summarize all the chapters, an RLM might look at that, and then it'll call a subagent to summarize each individual chapter. And then maybe it does one big summary at the end to combine everything. And then it returns that. So it's a very flexible strategy that can really do anything. I think of it as the generic inference time strategy that is very hard to do better than in accuracy. And you can improve a lot in cost and latency. Yeah. So I think about this as maybe you'll hate this, but it's like DSPy's answer to Claude code, right? It can—you know, you put it in a folder, essentially, you can say, hey, you can create as many subagents as you want to solve this problem. And then it can chunk that problem up into, okay, I'm going to send a subagent for each chapter, or I'm going to send one, just find this one thing out. And then you're not hitting that, that agent runs out of context. But the parent thread never does. Yeah. It's a very generic inference time strategy. And so there's really three situations that I think of for using it. I think the first is in super long context. Any long context problem, just default to RLM. The second is when it's helpful to do some sort of symbolic manipulation with whatever it's working with. And what that means is it can write code to actually manipulate things. So if you're combining summaries, it's way easier for it to do that in a for loop than manually by copying each summary into its context, right? You don't want to have to have it output all that. It can just write a for loop. The third is when you have tool calls that you don't want the model to have to actually call via outputting a native tool call. So if you want to summarize 12 things, you really don't want the model to have to write 12 parallel native tool calls. You just want it to write code that then does that. And so with those three things, the RLM can be very flexible and achieve pretty much any task. And do you find that you look at what the RLM did and then start using it as an inspiration for making it more deterministic? A hundred percent. I think it's very common to look at it and then take the functions that it constantly writes and maybe give those as tools because it's doing those over and over. And then when you take that to its extreme, you get to what we call DSPy flex, which is just code to represent your task. So DSPy flex starts as an RLM. It's a module that just says any inference time strategy underneath here is okay with me as long as it's good and works the best according to my signature. And so an optimizer will try a bunch of different combinations of modules and inference time strategies and decompositions to actually figure out what the best strategy is. Maybe it's an RLM with some prebuilt tools that the optimizer finds. Maybe it's some code as a heuristic and then an LLM call at the end as a fallback. So the optimizer gets to explore a lot of flexible strategies. But in the end, everything it writes is just coming straight back into your signature. Sure. And if that provably works better, then it will keep that. Is that the best way to characterize it? Exactly. Yeah. That's great. And then, what do you see going from here? Maybe it's a good one to end on. We now just have to provide a dataset, provide an eval metric, and provide inputs and outputs. Right? So are there any of those things flexible? Can we flex the eval metric, right? Can we flex that? Yeah, you're right on the money. So one of the optimizers that we're working on is a way to actually take unstructured feedback on examples and then help learn your metric and learn the actual dataset that you want to use. So it's a research project, so it's still in the works, but coming soon. And I'm very excited because oftentimes building a metric is one of the very hard parts of AI engineering. And so now it really becomes, can you get the feedback so that the system can then learn how to do your task? So what you're saying is, I was a prompt engineer at DSPy, put me out of a job. So I became head of evals and now you're going to automate that too. You're going to become a feedback engineer is what I'm saying. Feedback engineer. Okay. That's the next book. Um, cool. Well, I think someone came up with a slogan for DSPy. I think it was Raymond. What was the slogan for DSPy? I have to know what I want. Yeah. Yeah, that's always been the hardest thing. And I think DSPy, if you do find it difficult to adopt, just know that everyone struggles with that because what it does is it acts like a mirror, right? You—it shows back to you, hey, pretty much any problem is solvable if you put in the right structure. You just have to kind of know what problems you want to solve. And so it doesn't let you procrastinate on these things. And I think when people say they struggle with DSPy, I think what they're really struggling with is just that it's really hard to know what you want. Nice. Cool. All right. Thanks guys. I really appreciate you jumping on the live stream with me. You know, great to promote the book, but hopefully more than that, we've promoted DSPy and evals, because I still feel like it's very, very underrated. You know, this can be the source of a lot of jobs as people move from other things where AI solves that problem. And I think when people say they struggle with DSPy, I think what they really, if you introspect here, it's like what you're really struggling with is just like, it's really hard to know what you want. Nice. Cool. All right. Thanks guys. I really appreciate you jumping the live stream with me. Great to promote the book, but yeah, hopefully more than that, we've promoted DSPy and evals, because I still feel like it's very, very underrated. This can be the source of a lot of jobs as people move from other things where AI solves that problem. And so if more people can learn this stuff, I feel like they're going to have a lot more fun like we're having, and make a bigger impact too. Awesome. Thanks for having us, Mike. Awesome. Thanks, Mike. All right. Bye. And so, this is where, you know, we've done all the boring stuff, all the homework. We're ready to go. This is, like, where DSPy flies off the rails, right? Like, this is what the crowd is here for, right? It's to optimize your program. It says, this is how you get paid using DSPy. So, you know, DSPy has a lot of optimizers here that we can use out of the box. I would say you can't really go wrong with Jepa or Jepa. I still never know the right way to say that. Jepa. Jepa, okay, yeah. You can know because it conflicts with Jan Lacoon's Jepa, J-E-P-A. And on brand, Jan, at one point, did go to a talk that Lakshya, who is the creator of Jepa, was giving about Jepa. And he went purely because he was annoyed that someone already had a name that was a homonym for what he had created. And you know what his comment, he tweeted about it and said, told Lakshya he should change how it's pronounced to, you know, Jepa. Jepa. This is the new Jif, Gif thing, right? Yeah. But purely for Jan Lacoon to, like, make sure he has clean namespace here. Yeah, yeah. If you've upset Jan Lacoon, it means you're doing a good job in AI or anything. So we're going to get AI to optimize AI here, right? And this was, I think, one of the other key insights is that very early on, even GPT-4 era, we realized that if you point it in the right way, these models are already human-level prompt engineers. And I would say they're, like, probably past that now, like the above average versus the average human prompt engineering. But they're way more persistent, right? So they can try a lot more things than you or I would ever do. So the first thing you need to do is create, you know, another model here. This is a smarter LLM. I'm using Sol here. And we're going to use this model to rewrite the prompt, right? It's going to look at the failures and it's going to make change to the prompt, and then it's going to run it again. So it's not going to do the task, but it's going to teach the model that's doing the task how to do better job, right? So that's what you can think about it. So you pass in all of the failures or the, like, what comes out of Luna, and it is effectively asking Sol, hey, how would you change the job? How would you ask this, prompt this model better to get the ideal response? And, you know, we don't have time to run it. It takes about 15 minutes. It costs me about a dollar, I think, in OpenAI credits. But that's great because what we're doing here is we're training the judge, right? So our judge was already pretty good, 80%. We're going to see if we do a better job. And we passed in the AI detector. We passed in the training data and then the way it can validate. So this is, like, the holdout. And we've, you know, the important thing is we've given it that smart LLM to rewrite the prompt. So it's going to look, it's going to see whether it got the prediction right or not, and then it's going to rewrite the prompt. So, you know, this is what it looks like when it's optimizing. It's quite fun to watch if you haven't yet. You can see, here's an example where it's proposed a new prompt here, iteration three. And this is, like, how it's changing the prompt. It's coming up with its own rules. Like, you don't have to write this, which is amazing and radicalizing where you see it. And, you know, it's going to keep going. It's going to score. And then, you know, eventually it's going to get to the point where you see how well it's done. And, you know, you can see we actually got, in this case, it got 20 of 20 examples correct, right? So we went from 80% up to 100%. And what's funny is, like, each model has its own weird nuances sometimes. Like, there was a person who I remember maybe a year ago was running a bunch of evals on JEPA, like, runs on GPT OSS 20B. So the small, super fast model. And they would look at the prompts that they arrived at. And for some reason, and there was a bunch of different tests, but all of the winning prompts ended with good luck. Which I just love. It's just, like, these weird ablation or weird, like, things baked into the model. Yeah. And that's the thing. It's, like, you don't have to care about, like, what weird thing works for that model, right? Like, we can rerun this again, and we can get to 100% with a different judge or maybe a cheaper model, right, next time. And it might require more hand-holding or less hand-holding. We can save our program. Always good to do that once you have run it so you don't waste that dollar, you know, in spend. But then, you know, you can use that. So you can see it's got 100% here. You can use that to now optimize the original task. So I'm going to speed through here. You can look at the prompt if you like, and you can see it's learned a few of these rules. Like, do not classify text as error generated merely because it's grammatical, generic, brief, or summarizes an idea. So it's, like, figured out what, you know, what actually works, right? And so you can be really confident in these instructions. Like, it's going to be much better than if you just ask Claude to write this, right? Because it's proven that these rules have earned their place, right? Like, if it added a rule that didn't work, it would have taken it back out. Yeah. And there's something else that's really important about this. And this applies to a question that, Mike, you were asking me earlier for this call is, like, what's the difference between, say, JEPA handing it to Claude or even auto research or similar things? Or even the meta harness paper? Yeah. And I think what's really important about this is that JEPA tends to win both in cost and the ceiling at what it can deliver because it kind of, of how it manages the context. It's kind of, and how it tests these things. So if it comes up with a winning prompt, it then uses that as the starting point to try out different kind of variations and then kind of test those in a genetic Pareto front. Hence, that's what JEPA stands for. And that additional structure turns out to bump the model out of distribution to find novel ideas. Yeah. Another researcher who works with Lakshia at UC Berkeley, Sheng Yen Tan, wrote a paper a couple weeks ago about how important forgetting is, especially in auto research, which is auto research. So the fork and flush thing? It's related to fork and flush. So I wrote this up on my blog as context inertia. So it covered Anthropix paper that touched on it, fork and flush, and Sheng Yen's paper about forgetting. And they all came to the same conclusion, which is for long horizon tasks or optimizations, at some point, the model hyper focuses on a solution. And it ignores better solutions that might require some lateral thinking. And the way to get out of this is you just delete the context. So fork and flush called it flushing. Sheng Yen called it forgetting. What I loved about Sheng Yen's paper is it talked about how he showed that the longer your context got, the less the model thought, like the reasoning tokens were shorter as it went on. And the size of the edits, which to me is like the biggest issue, got shorter and shorter and shorter and shorter. And if you forget, delete the context, it kind of resets it and bumps it back up. It's incredible. This also works for humans as well, by the way. Oh, yeah. A hundred percent. I will go. We'll go get some mushrooms. Maybe some alcohol. Just. I prefer a bonk on the head. Yeah, that too. Yeah. And actually, I'd like to see you go head to head with Jeff actually. Yeah. Yeah. Cool. All right. So I want to save some time for questions. So I just want to kind of show you what we can then do. Right. We're passing that trained judge. The one that now is a superstar. It gets a hundred percent. And it like a hundred percent agrees with me on this specific data set. Right. And you're not always going to get to a hundred percent. But like I'm fairly confident now in this judge and I can use it to optimize my task. So when someone asks you, like, how do I optimize something that I don't know the right answer? The answer is you find something else. You build a data set to train your judge. And then once you have a judge that you like, you can use it to train the original task. So here it's same, same setup. And you can, like, hopefully it's getting boring in a good way now. You know, you're passing it to Jepa. You're passing in your metric. In this case, it's the optimized LLM judge and not the original one. And then you're passing in the smart LLM still because in this case, you want this LLM to rewrite the task prompt now. And, you know, lo and behold, like, we go through. We run, run, run, run, run, run, run. And bear in mind, this judge was not being tricked at all before this. And then we get to, this is the prompt that it's written for us, which I'm not going to go into. But here we go. Now we're getting a 70%, right? So we took that, you know, mutated, you know, evolutionary apex judge that Jepa found for us. And we've managed to now give the same treatment to the original task. So now the task, you know, the task that humanizes the text, tries to trick the judge, try to make it sound like human text, has scored a 70%. So it's not tricking the judge every time, but it's gotten a lot better at tricking the judge. And you can keep going back and forth with this. This is the exact process that I used to create AI personas that sounded like real people, you know, with Ask Rally. And I've used this optimizer evaluator pattern, like, on basically every project I've worked on. Yeah, no, it's incredible. And I think the other thing is that that's one of the things that's so nice about once you learn kind of the primitives in DSPy. Is it applies to every project? And it helps you get upset up really quickly. One of the things that we want to work on is just a general DSPy, like, bootstrapping skill to adopt it. Because there's so many, just having your code being laid out this way is super handy. In fact, I even use it. So I have a Py plugin for the coding agent that uses a decision model to detect different failure modes that smaller models might get caught in. And so, like, looping or drifting off the task or, like, other things like that. And so one of the other researchers at UC Berkeley we work with, Melissa Pan, has a training set that's, she calls it MAST, measuring, I forget. It's agent failure taxonomies. And she has a training set of these things. And I built the DSPy, you know, decision model program to say, hey, is this training, like, is this failure mode being hit and using it to detect it? And I optimized everything, figured out all of the cuts, the right questions to ask with, ask the decision model. And then I output that program and then just had my coding agent rewrite that for me and type save. So I kind of had my compiler over here. And then I would ship it over here. And what that enables me to do is if Melissa makes new training data or I have new training data, I still can recompile it over here and then reship it and translate it. Yeah, that's great. And you can obviously, like, I'll share this. You can read this. I went on a little bit further. I, you know, started showing off. Like, one of the fun things you can do is you can just, you know, it's all in DSPy, right? So you can just do this. This is called best event. You can run it multiple times and then just take the best one, right? So, like, which one tricks the judge the most, right? This is, I think, the connection that, you know, a lot of people live in DSPy and Jupyter Notebooks. One of the things I think is underrated is taking the evals that you've trained and then putting them in production. Because if you have a text humanizer tool that you're putting out there, why not just, like, rewrite the text 10 times and then use your DSPy judge to see which one is the best one? Yeah, I'm currently dogfooding something for us. Isaac correctly bothered me about it yesterday. So, Isaac, I went through my Hermes agent and I have some skills and, like, cron jobs. And so I'm now starting to run my meeting debriefs. So it takes my transcript and then it outputs, you know, who was there, what are the decisions to be made. And then the other one is I have another one that reads the minutes of my local city council and tells me if there's anything to pay attention to. And that's actually a really hard eval because some things appear really boring, but I care about them. And so, like, both of these things are getting DSPied and then we're going to be hosting them and then I'll continue to feed back at them and they're just kind of tools. So, yeah. Yeah, great. And one last thing here is just to show you how easy it is. Like, you know, we were working on this model. We got 75% now. The best event improved a little bit. And then we can drop in Gemini. We can say, hey, a new Gemini model came out. This isn't a new model. This is an older one. But, you know, you could, like, say, you know, you want to try Argon on this, right? Like, is this a really good detector? You can now just do that, right? And then you can see here that we then bumped it up to 85%. So now you have to decide, hey, is it worth it for the extra money? You know, could I, like, how reliable does it need to be before it ships to production? And you can make those tradeoffs with your manager. And I was, you know, I started my work in performance marketing or you run Facebook ads and you, you have to make $2 for every dollar you spend, right? And I feel like DSPy is one of those things that can help you do that in AI as well and show the ROI of the task, which is something that, you know, is escaping most people right now. Yeah. And I think that's, like, one of the things that I think is, like, as you adopt DSPy, and I know, Mike, you feel this, which is, like, as you build your eval, like, that is gold. And when I say gold, I mean, like, literal currency. Like, you can run that against everything. And it's continually, like, new model, new whatever. You just keep running it. Yeah. I mean, obviously, I just wrote a book on this, so I'm pretty biased. You know, if you want to check this out, like, I tried not to make it too much of a sales pitch for my book, more for DSPy, the open source library. But, you know, it is live on O'Reilly right now. It is on Amazon. I made this book specifically because I looked at the DSPy website originally, and I thought, I am too dumb to use this tool. And I still think I'm one of the dumbest people that uses DSPy. The documentation used to be really hard. Yeah. It's very academic, right? Like, it was made out of Stanford, MIT, et cetera. Right? Like, so it's, you know, I feel like me asking a lot of dumb questions has maybe helped evolve the library over time. But I realized that, like, not everyone has that persistence. And honestly, like, you know, DSPy paid me back with this, right? Like, it's amazing. Like, I was freelancing. You realize how easy it is to freelance when you're like, hey, I tried a new thing. This new model performs, like, 50% better. Like, thank you very much. Right? Like, it's, like, pretty great thing to say to a client. And so if you can define the value and DSPy forces you to do that, then, you know, you can really show that return. And I think that that's the key here. And hopefully more people get into DSPy. I have this conspiracy theory that, you know, everyone's using DSPy, but nobody's really talking about it because it's, like, too good to share, you know? Yeah. Look, I've heard that a number of times of companies thinking it's their secret sauce. And so they won't talk about it. Yeah. They will say it to us because we'll reach out and we'll say, like, how are you using that? And then they'll, like, we aren't maintaining it. And it's a little cloak and dagger you have to go through. By the way, I will turn this into a sales pitch for your book because this book is excellent. I have read it through it. And if anyone is interested in this, the other thing that's great about it is, first off, I want you to use DSPy. And I think this is the best way for you to get started with DSPy. But even if you bounce off DSPy, and if you do, let us know because I want to understand so that we can build the best library for whatever use case it is. But even if it's not your use case, everything in here is, like, the way to understand context engineering as a structure and practice and can translate to any harness or framework you start building in. And it's pretty powerful. I think any team that ends up adopting the best eval practices just ends up building DSPy. And so Mike's book teaches you the best practices to just use DSPy from the start so that you don't have to run into roadblocks and then get there. Yeah. I had kind of built DSPy in Langchain at the time. And I was like, I had a really shitty offer. And then I was like, oh, okay. Yeah, I get it. Yeah. There's a great question about can non-technical users try this out if I'm only working at the Claude Code projects level? I think 100%. And I think the thing that is great about it, as we kind of said earlier, is, like, if you're not a technical coder and you aren't used to reading code, the language that your model might come up with to structure your task might be really hard. But if you say, hey, use DSPy to build this, you're going to get code you can actually read and edit, which is because it's just well structured to be read and understood by humans. So, yeah, I think. And the other thing that's great about DSPy, having the interface essentially having not changed since pre-ChatGPT, is that it's deeply in the weights. There's a couple, like, failure modes that it will figure out, like, when it hooks up to the model, like, it'll put in temperature or other things that may not work. But your agent will figure that out. But it knows how to write signature and it knows how to do all of the other stuff. So, strongly recommend. And then, yeah, big, strong yes. Great. So, yeah, I don't know if you guys have a few more minutes maybe for questions you want to hang on. Definitely. I'm happy to do. Because this question is one we get a lot, which is how many samples do you need to optimize? Yeah. Well, in that example there, I try and optimize with as few examples as possible. I find that even just, like, one turn with Jepa, right, it's a better prompt than I was going to write, but, but yeah, in that example I had, like, I think it was 20 examples. So it's, it's, it's not, it's not a huge amount to get started. It's probably going to be what you would have done manually and it will do it faster. But I would say the real sweet spot is, like, when you get north of, like, around 50. Would you say that was similar? Yeah, I think it depends on the task. Like, if you're doing something that you're, like, trying to match exact data to one another, like, you might want 100, 200, that, you know, might be the answer that Lakshia and team will say. But also keep in mind, Lakshia built Jepa originally to, like, improve an agent's ability to use documentation for, like, I think it was, like, a Qualcomm instruction set for some sort of, like, hardware chip. And he had, like, 40 examples in that original one. So I do think less examples is fine. But the other thing is, is this is kind of the corollary of vibe coding to look at your data. The other thing you can do, too, is, like, I have definitely said, hey, this is a failure mode I'm seeing. Can you synthesize some inputs that might evoke this failure mode that I can label? And that works really, really well, too. The thing that I want people to take away when building their eval data is that if, if, if you have a prompt and you're iterating in your prompt to build your system, you're going to add these one-liners, these little hot fixes saying, not like that, not like that, not like that. And then when you change to a model, you're going to have to go through each of those individually. If you spend a little bit more effort instead of saying, not like that in a markdown file, but instead of, instead say, not like this with an example, that is going to last forever. It is going to be a piece of value that you carry forward with this program definition throughout its life. So I really encourage you to invest that time. Yeah, that's, I'm going to steal that. I love that example of why example is great. I wanted to, Isaac, I wanted to hear you speak a little bit about RLMs, if you have the time, and flex, and then kind of join that into like, what's the future of DSPy? Because I think maybe another underrated thing people don't realize is that DSPy seems to be either like ahead of the curve or like very much on top of the curve, like with Jeff, like for, for these new innovations coming out. Do you want to just explain, first of all, maybe RLMs and then flex, because I think they're kind of related topics. Yeah. So RLMs are an inference time strategy that's very flexible. It basically is the equivalent of code mode for an LLM, where you give it all of the variables and your inputs in its, you give all of its inputs as variables inside of a Python REPL, and you say, hey, write code in order to do this signature. So if you have a book and you want to, you know, summarize all the chapters, well, an RLM might look at that, and then it'll call a subagent to summarize each individual chapter. And then maybe it does one big summary at the end to combine everything. And then it returns that. So it's a very flexible strategy that can really do anything. I think of it as the generic inference time strategy that is very hard to like do better than in accuracy. And you can improve a lot in cost and latency. Yeah. So I think about this as like, maybe you'll hate this, but it's like, it's like DSPy's answer to Claude code, right? Like it can, you know, it can, you put it in a folder, essentially, you know, you can say, hey, you can create as many subagents as you want to solve this problem. And then it can chunk that problem up into like, okay, I'm going to, you know, send a subagent for each chapter, or I'm going to send one, just like find this one thing out. And then you're not like that, that agent runs out of context. But, but like the parent thread never does. Yeah. It's a very generic inference time strategy. And so there's really like, there's three situations that I think of for using it. Um, I think the first is in super long context. Is that any long context problem, just default to RLM. Um, the second is when it's helpful to do some sort of symbolic manipulation with whatever it's working with. And what that means is just, it can write code to actually manipulate things. Um, so if you're combining summaries, it's way easier for it to do that in a for loop than manually by copying each summary into its context, right? You don't want to have to have it, uh, output all that it can just, um, write a for loop. The third is, uh, when you have tool calls that you don't want the model to have to actually, uh, call via outputting a native tool call. So if you want to summarize 12 things, you really don't want the model to have to write 12 parallel native tool calls. You just want it to write code that then does that. Um, and so with those three things, the RLM can kind of do, be very flexible and achieve pretty much any task. And, um, then do you, do you find that you like look at what the RLM did and then, and then start using it as an inspiration for, um, making it more deterministic? A hundred percent. I think it's, it's very common to, um, look at it and then, you know, take the functions that it constantly writes and maybe give those as tools because it's doing those over and over. Um, and then when you take that to its extreme, you get to what we call DS by flex, um, which is just code to represent your task. So DS by flex starts as an RLM. Um, it's, so it's a module that just says any inference time strategy underneath here is okay with me as long as it's good and works the best according to my signature. And so an optimizer will try a bunch of different combinations of modules, um, and inference time strategies and decompositions to actually figure out what the best, uh, best strategy is. Um, and so maybe it's an RLM with some prebuilt tools that the optimizer finds. Maybe it's some code as like a heuristic and then a, um, and then an LLM call at the end as like a fallback. Um, so the optimizer gets to explode a lot of explore a lot of flexible strategies. Um, but you know, in the end, everything it writes is just coming straight back into your signature. Sure. Um, and if that provably works better, then it will keep that. Uh, is that the best way to characterize it? Exactly. Yeah. Yeah. That's great. And, and then, um, what, what do you see going from here? Maybe it's a good one to end on. It's like, you know, like, uh, we, you know, the last, like all we have to do now is provide a dataset, provide an eval metric and, uh, provide inputs and outputs. Right. So like, you know, are there any of those things flexible? Like, uh, can we flex the eval metric, right? Can we flex, you know, this? Yeah, you're, you're right. You're right on the money. Um, so one of the, one of the optimizers that we're working on is a way to actually take unstructured feedback, um, on examples and then help learn your metric and learn the, learn the actual dataset that you want to use. Um, so it's, it's a, it's a research project, so it's still, still in the works, but, you know, coming soon. Um, and so I'm very excited because oftentimes building a metric is one of the very hard parts of AI engineering. And so now it really becomes, can you get the feedback so that the system can then learn, um, learn how to, how to do your task. So, so what you're saying is, uh, I, I was a prompt engineer at DSPy put me out of a job. So I became head of evals and now you're going to automate that too. You're going to become a feedback engineer is what I'm saying. Feedback engineer. Okay. Okay. That's the next book. Um, cool. Well, I think there's, there's someone's slogan. They came up for, for DSPy. I think it was Raymond, which is the slogan for DSPy should be great. Now I have to know what I want. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. That's, that's always, that's always been the hardest thing. Um, uh, you know, and, uh, and, and, and, you know, I think, um, uh, like DSPy, if you, if you do find it difficult to adopt, uh, just know that like everyone struggles with that because, uh, what it does is it's, it's, it acts like it's a mirror, right? You, it shows back to you like, Hey, pretty much any problem is solvable. If you put in the right structure, you just have to kind of know what problems you want to solve. And, uh, so it doesn't let you procrastinate on these things. And I think when people say they struggle with DSPy, I think what they really, you know, if you, if you're introspect introspect here, it's like what you're really struggling with is just like, it's really hard to know what you want. Nice. Cool. All right. Thanks guys. I really appreciate you jumping the live stream with me. Um, you know, great to, uh, you know, promote the book, but, uh, but, but yeah, hopefully more, more than that, we've promoted DSPy and, and, and evals, um, uh, because I, I still feel like, uh, it's, you know, very, very underrated. Um, you know, this is, uh, can be the source of a lot of jobs as, as people, um, you know, move from other things where, where AI is, uh, solve that problem. Uh, and, and so, uh, if more people can learn this stuff, I feel like, uh, they're going to have a lot more fun like we're having, um, and, uh, and, and make a bigger impact too. Awesome. Thanks for having us, Mike. Awesome. Thanks, Mike. All right. Bye.