---
title: "How to Use DSPy for Internal Tools: Compiled Prompts, Not Hand-Tuned Ones"
url: "https://goremy.ai/blog/articles/how-to-use-dspy-for-internal-tools-a-practical-guide"
author: Josh
editor: Josh
editor_title: Chief of Staff, GTM & Product
published: "2026-10-01T10:00:16.118Z"
updated: "2026-10-01T10:00:16.118Z"
topic: AI Agents & Automation
description: How to use DSPy (and its Elixir port Imp) to compile internal AI workflows into versioned, testable software instead of renting another SaaS AI feature.
---

# How to Use DSPy for Internal Tools: Compiled Prompts, Not Hand-Tuned Ones

> How to use DSPy (and its Elixir port Imp) to compile internal AI workflows into versioned, testable software instead of renting another SaaS AI feature.

Edited by Josh, Chief of Staff, GTM & Product · Published 2026-10-01

## How do you use DSPy for internal tools instead of hand-tuning prompts?

You use DSPy for internal tools by treating your prompt as a compiled program, not a string. Define a typed signature for the task, write a metric that scores success, pick an optimizer, and let it search for the instructions and examples that actually work. Swap the underlying model later and recompile instead of rewriting prompts by hand.

That's the whole idea. The rest of this piece is implementation detail, plus why Claude Opus 5.5 has made experimenting this way cheap enough to do properly.

## TL;DR

- DSPy turns a fragile prompt into a **versioned, testable program** built from a signature, a metric, and an optimizer.
- Enterprises average 118 SaaS apps with roughly half the licenses unused, so **internal AI tools** can be a cheaper alternative to another subscription.
- Shopify moved a workflow onto a much smaller model with GEPA and ended up with a solution **roughly 75 times cheaper** and about twice as reliable.
- Imp brings DSPy's automated prompt optimization natively to the **BEAM virtual machine**, so Elixir and Erlang teams avoid a Python sidecar.
- Opus 5.5 cuts net costs for typical workloads by roughly 40%, which makes **frequent recompilation** affordable.
- The optimization loop only works if you have a **labeled dataset and a metric**, so check for those before you start.

## Why does 'just prompt it' break down at scale?

Most internal AI tools start the same way. Someone writes a prompt, tests it on five examples, ships it. It works fine until the model gets upgraded, the input distribution shifts, or someone edits one line and quality quietly drops. Nobody notices until a downstream report is wrong.

Meanwhile the SaaS answer to the same problem is to buy another AI feature bolted onto an existing tool, or a new point solution entirely. Enterprises already run an average of 118 SaaS apps, up from 106 the year before, an 11% year-over-year climb, and roughly half those licenses go unused. [1] Adding an AI-flavored subscription for every workflow that could be a fifty-line internal program is how that number keeps growing. The teams that have already lived through this math on other categories of tooling know [niche SaaS is losing ground to build-vs-buy defaults](https://goremy.ai/blog/articles/build-vs-buy-internal-tools-with-ai-why-saas-is-losing) for exactly this reason.

**Average SaaS apps per company keeps climbing**

| Year | Average SaaS apps per company |
| --- | --- |
| Last year | 106 apps |
| This year | 118 apps |

_11% year-over-year growth, with roughly half of licenses going unused._

The underlying problem isn't that prompts are a bad idea. It's that a hand-written prompt has no test suite, no versioning discipline, and no way to know if it still works after a model swap. DSPy exists to fix that.

## What is DSPy?

DSPy, from Stanford, reframes the job as programming, not prompting. [2] Instead of hand-crafting a prompt string, you define three things:

- **A signature.** A typed description of inputs and outputs for a task, like a function signature but for a language model call. [2]
- **A metric.** A scoring function that tells the system whether an output was good, not a vibe check.
- **An optimizer.** An algorithm, such as BootstrapFewShot, MIPROv2, or GEPA, that searches for the instructions and few-shot examples that maximize the metric against real examples. [2] [3]

The optimizer then compiles your program: it translates the signature and metric into model-specific instructions that actually work for the model you're running. [2] Change models and you recompile. You don't manually rewrite the prompt and hope.

GEPA is worth naming specifically because it's the optimizer doing most of the current heavy lifting. It uses a separate reflection model to read execution traces and textual feedback on failures, then rewrites instructions accordingly. A light-budget run evaluates roughly six candidate prompts before stopping, and critically, the same base signature compiles into different optimized instructions depending on which model you deploy it against. [3] That's the part that matters for internal tools: you're not maintaining one prompt per model, you're maintaining one signature and letting the optimizer handle the translation.

Adoption critics have a fair point buried in the enthusiasm: DSPy's real value is the optimization loop, and that loop needs a dataset and a defined task to run against. [4] If you don't have either, you're not ready for this yet. Keep that in mind before step one below.

## What is Imp, DSPy's port for the BEAM?

If your internal tools already run on Elixir or Erlang, you don't need to bolt on a Python service just to get DSPy's optimizer discipline. Imp ports DSPy's core concepts to the BEAM virtual machine: signatures, modules, and optimizers including MIPROv2 and GEPA. [5] [6] The project ships an explicit "Imp for DSPy Users" guide mapping concepts across the two ecosystems and documenting where BEAM's runtime differs from Python's, and it publishes honest conformance numbers rather than claiming one-to-one parity. [6]

The pitch for Imp isn't that it beats DSPy technically. It's that teams running BEAM infrastructure get compiled-prompt discipline without a separate language runtime, a separate deploy pipeline, and a separate on-call rotation for a Python sidecar. For a lot of internal tooling teams, that operational simplicity is worth more than framework maturity.

## How do you build an internal tool with DSPy, step by step?

Here's the actual workflow, whether you're using DSPy in Python or Imp on the BEAM.

1. **Write the signature first.** Define exactly what goes in and what comes out. Resist the urge to write instructions yet. A signature for a support-ticket triage tool might be: ticket text in, category and confidence score out.
2. **Collect 30 to 100 labeled examples.** This is the step people skip and the step that makes everything after it work. Without examples, the optimizer has nothing to search against.
3. **Write a metric, not a vibe.** Decide programmatically what counts as a correct output. Exact match, a scoring rubric, or a secondary LLM judge all work, but it has to be a function you can run in a loop.
4. **Pick an optimizer.** Start with something cheap like BootstrapFewShot for a first pass. Move to MIPROv2 or GEPA once you have a metric and dataset that justify the extra compute. [2] [3]
5. **Compile.** Run the optimizer against your dataset and metric. It will generate and test candidate instructions automatically, something a light GEPA budget does in around six rounds. [3]
6. **Evaluate on held-out data.** Don't trust the training-set score. Hold back examples the optimizer never saw.
7. **Swap models and recompile, don't rewrite.** When a cheaper or faster model becomes available, rerun the compile step against the new model rather than manually re-tuning the prompt.

That last step is the entire point of the exercise. It's also where the return on investment shows up fastest.

## What does a real example look like: Dropbox Dash's relevance judge?

Dropbox's Dash team built an LLM-as-judge system to score search relevance. Manual prompt tuning got them a functioning judge, but quality plateaued early, and every model swap or small prompt edit risked regressions. [7] They brought in DSPy to turn that manual, fragile process into a repeatable optimization loop against a measurable objective. [7] DSPy-driven optimization is now used across more than 30 prompts in Dash's stack. [8]

**Dropbox Dash's DSPy footprint**

- 30+: Prompts across Dash's stack now tuned with DSPy optimization

Shopify ran a similar experiment: they converted a single hand-written GPT-5 prompt task into a DSPy program, moved it onto a much smaller Qwen model, and optimized it with GEPA. The result was a solution roughly 75 times cheaper and about twice as reliable as the original large-model prompt. [3] That's not a marginal efficiency gain. That's the difference between running a workflow on a premium model forever and running it on hardware that costs a fraction as much, with better accuracy, because the instructions were tuned for that specific model rather than borrowed from a bigger one.

**Shopify's GEPA-optimized migration off GPT-5**

- 75×: Cheaper to run than the original hand-written GPT-5 prompt
- 2×: More reliable than the original prompt
- 6: Candidate prompts evaluated in a light-budget GEPA run

## Where does Claude Opus 5.5 fit in?

DSPy and Imp handle the automated half of prompt engineering: searching for instructions that work against a metric. But Anthropic's own guidance for Claude Opus 5.5 makes clear that model-specific, highly situational prompting still matters on top of that. The documentation recommends starting effort at medium rather than defaulting to maximum reasoning, noting that Opus 5.5 at medium effort matches or exceeds Opus 5 at high effort on coding and knowledge-work evaluations. [9] It also gives precise instructions for unattended agent loops and notes the model resists indirect prompt injection better than any earlier Opus release. [9]

That's the layer DSPy automates rather than replaces. Your signature and metric stay stable. The optimizer's compiled instructions absorb model-specific quirks like effort calibration or injection resistance, so you're not manually re-deriving them every time Anthropic ships an update.

The economics make this cheaper to run than it used to be. Opus 5.5 launched at $4 and $20 per million input and output tokens, 20% less than Opus 5, with cache reads at $0.20 per million tokens, a 60% cut. [10] Combined with output generation more than 30% faster, Anthropic puts the net cost reduction at roughly 40% for typical workloads. [10] Frequent recompilation against a metric, which used to be an expensive habit, is now a cheap one. Teams comparing model options for internal workloads are already running these tradeoffs against [flash-tier alternatives like GLM and Qwen](https://goremy.ai/blog/articles/glm-5-3-flash-vs-qwen3-8-flash-which-wins-for-internal-tools) for the same reason.

**Claude Opus 5.5's cost and speed profile**

- 40%: Net cost reduction for typical workloads vs. Opus 5
- 30%: Faster output generation vs. Opus 5
- 60%: Cheaper cache reads per million tokens vs. Opus 5

## When does building beat buying another SaaS seat?

The honest case for doing this internally instead of renting an AI feature comes down to control and cost compounding. A DSPy or Imp pipeline is versioned in your repo, tested against a dataset you own, and portable across models as pricing shifts. A SaaS AI feature is a black box you pay per seat or per conversation, with no visibility into what's happening when the vendor swaps models underneath you. That's the same argument already playing out in [agent orchestration built on open frameworks and MCP](https://goremy.ai/blog/articles/build-vs-buy-ai-agents-how-to-build-internal-workflows) instead of per-seat agent platforms.

**Build vs. buy: where a compiled prompt pipeline fits**

| Option | Upfront setup effort | Cost as usage scales | Resilience to model swaps | Auditability / version control | Charges per seat or conversation |
| --- | --- | --- | --- | --- | --- |
| SaaS AI feature | low | high | low | low | Yes |
| Hand-tuned prompt | low | medium | low | low | No |
| DSPy / Imp compiled pipeline (recommended) | high | low | high | high | No |

_Ratings are relative across these three options, not absolute scores._

The pressure toward building this in-house is already there whether or not it's sanctioned. Independent surveys put shadow AI usage anywhere from about 50% to over 80% of employees, depending on methodology, and a large share say they'd keep using unapproved tools even if the company banned them outright. [11] [12] People are already solving these problems with whatever chatbot they have open. The question for engineering leadership isn't whether employees are doing this. It's whether to formalize it into something owned and testable. Teams that make that formalization intentional end up closer to the orchestration discipline [Remy](https://goremy.ai) applies to internal AI workflows than to a vendor's opaque feature toggle.

## How do you make shadow AI accountable through governance?

Governance is the part most teams skip until an audit forces the question. Only about 15% of organizations have implemented formal AI governance policies, despite clear evidence that usage is already widespread. [13] Roughly 78% of employees use AI tools without IT approval, and 46% say they'd keep doing it even if explicitly prohibited. [13] UpGuard's numbers put employee usage of unapproved tools at 81%, with 88% of security leaders reporting the same behavior among their own staff. [12]

**Shadow AI behavior inside the average enterprise**

|  | Share of respondents |
| --- | --- |
| Use AI tools without IT approval | 78% |
| Would keep using unapproved tools if banned | 46% |
| Share confidential data with external AI platforms | 38% |
| Orgs with formal AI governance policies | 15% |

An internal DSPy or Imp pipeline doesn't automatically fix that gap, but it changes what governance is possible. A compiled prompt lives in version control. Its metric and evaluation results are logged. You can point an auditor at the exact dataset a prompt was tuned against and the exact score it produced. None of that exists when the actual workflow is an employee pasting company data into a personal chatbot tab.

## What checklist shows whether this is the right fit for your team?

Before committing engineering time to a DSPy or Imp pipeline, check whether the workflow actually qualifies:

- **You have or can build a labeled dataset.** No dataset means no metric means no optimizer, full stop. [4]
- **The task repeats often enough to matter.** One-off analysis doesn't justify a compiled pipeline. A daily or hourly workflow does.
- **You've already hit a model-swap wall.** If changing models broke your prompt once, it will again, and that's the exact pain DSPy addresses. [7]
- **You're already running BEAM infrastructure**, in which case Imp avoids adding a Python service just for this. [5] [6]
- **The current SaaS alternative charges per seat or per conversation** for something a fifty-line typed program could do at a fraction of the cost, the same math driving [teams to build internal tools instead of renting them](https://goremy.ai/blog/articles/build-vs-buy-internal-tools-how-ai-coding-changed-the-math).

If most of those check out, you're not choosing between a prompt and a subscription. You're choosing between renting a black box and owning a program you can test, version, and swap underneath as models get cheaper.

## Frequently Asked Questions

### What is DSPy used for?

DSPy lets developers define an AI task as a typed signature and a measurable metric, then uses optimizers like MIPROv2 or GEPA to automatically generate and test the instructions that best satisfy that metric, rather than hand-writing a prompt string. [2]

### Is Imp the same as DSPy?

No. Imp is a separate, independently maintained port of DSPy's core concepts, signatures, modules, and optimizers, to the BEAM virtual machine used by Elixir and Erlang. It documents where its behavior differs from Python DSPy rather than claiming exact parity. [5] [6]

### Do I need a large dataset to use DSPy for an internal tool?

You need enough labeled examples for an optimizer to search against, generally a few dozen to a hundred. Without a dataset and a metric, there's nothing for the optimizer to optimize, which is the main reason some teams find DSPy overkill for ad hoc tasks. [4]

### How does Claude Opus 5.5 relate to DSPy or Imp?

DSPy and Imp automate the search for effective instructions against a given model. Claude Opus 5.5's prompting documentation supplies model-specific guidance, like effort calibration and injection resistance, that the optimizer's compiled instructions need to account for when targeting that model specifically. [9]

### Is building an internal DSPy pipeline cheaper than buying an AI SaaS tool?

It depends on usage volume and how often the workflow needs to change models. Shopify's DSPy and GEPA migration to a smaller model cut costs roughly 75x while improving reliability about 2x, which is the kind of gain that outpaces per-seat SaaS pricing once a workflow runs often enough. [3]

## Sources

1. [The big list of SaaS statistics that you should know](https://www.bettercloud.com/monitor/saas-statistics/) (BetterCloud)
2. [What is DSPy?](https://www.ibm.com/think/topics/dspy) (IBM Think)
3. [GEPA optimization — Getting Started](https://dspy.ai/current/getting-started/gepa-optimization/) (DSPy documentation)
4. [If DSPy is so great, why isn't anyone using it? (Hacker News discussion)](https://news.ycombinator.com/item?id=47490365) (Hacker News)
5. [Imp is a full port of DSPy to the BEAM (Hacker News discussion)](https://news.ycombinator.com/item?id=49869995) (Hacker News)
6. [deepfates/imp — GitHub repository](https://github.com/deepfates/imp) (GitHub)
7. [How we optimized Dash's relevance judge with DSPy](https://dropbox.tech/machine-learning/optimizing-dropbox-dash-relevance-judge-with-dspy) (Dropbox Tech Blog)
8. [Building Production-Scale AI Search with Knowledge Graphs, MCP, and DSPy](https://www.zenml.io/llmops-database/building-production-scale-ai-search-with-knowledge-graphs-mcp-and-dspy) (ZenML LLMOps Database)
9. [Prompting Claude Opus 5.5](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/prompting-claude-opus-5-5) (Claude Platform Docs (Anthropic))
10. [Claude Opus 5.5](https://www.anthropic.com/claude-opus-5-5) (Anthropic)
11. [The Shadow AI Surge: Study Finds 50% of Workers Use Unapproved AI Tools](https://www.securityweek.com/the-shadow-ai-surge-study-finds-50-of-workers-use-unapproved-ai-tools/) (SecurityWeek)
12. [The State of Shadow AI - Trends, Insights & Statistics](https://www.upguard.com/resources/the-state-of-shadow-ai) (UpGuard)
13. [Shadow AI Is the New Shadow IT: 78% Use AI Without IT Approval](https://www.digital-chiefs.de/en/shadow-ai-is-the-new-shadow-it/) (Digital Chiefs)
