Skip to content

DSPy vs guidance

Which should you use? A side-by-side look at what each one does, who it suits, what it costs, how hard it is to set up, and where each falls short.

DSPy

Open source · MIT

A Python framework for building and optimizing language model programs instead of hand-writing prompts.

guidance

Open source · MIT

A Python library for steering language models so their output follows a set structure.

The short answer

Choose DSPy if you need…

  • Python developers building LM-based pipelines such as RAG or multi-step agents
  • Teams that want to improve prompts with measurable optimization instead of manual tweaking
  • Researchers experimenting with prompt and weight optimization methods
  • People who already have a way to measure output quality and want to tune against it

Choose guidance if you need…

  • Python developers who need model output in a predictable format, such as JSON-like or fixed-choice answers
  • Developers who want to run a model locally through backends like Transformers or llama.cpp
  • People building multi-step model workflows that mix generation with ordinary code
  • Developers who want to test grammars offline using the included Mock model

Side-by-side

DSPyguidance
TypeLibraryLibrary
PriceFree and open sourceFree and open source
LicenceMITMIT
GitHub stars38.9k21.8k
Setup difficultyIntermediateIntermediate
How you get itInstall with a package managerInstall with a package manager
PlatformsAPI, Linux, macOS, Windows—
Works withOpenAI, Anthropic—
Main languagePythonJupyter Notebook
Last code update5 days ago6 months ago

What each one is

DSPy

DSPy is a Python framework for building AI systems out of modular code rather than long hand-written prompts. You describe what each step should do in Python, and DSPy provides algorithms to optimize the prompts and model weights behind those steps. The README says it is used for simple classifiers, RAG pipelines, and agent loops.

guidance

Guidance is a Python library for controlling how a language model writes its output. Instead of only writing a prompt and hoping for the right format, you can constrain generation with patterns like regular expressions or grammars, and mix in plain code such as conditionals, loops, and tool use. The README says this aims to give structured, higher-quality output while reducing latency and cost compared with conventional prompting or fine-tuning.

Best for

DSPy

  • Python developers building LM-based pipelines such as RAG or multi-step agents
  • Teams that want to improve prompts with measurable optimization instead of manual tweaking
  • Researchers experimenting with prompt and weight optimization methods
  • People who already have a way to measure output quality and want to tune against it

guidance

  • Python developers who need model output in a predictable format, such as JSON-like or fixed-choice answers
  • Developers who want to run a model locally through backends like Transformers or llama.cpp
  • People building multi-step model workflows that mix generation with ordinary code
  • Developers who want to test grammars offline using the included Mock model

Strengths

DSPy

  • Declarative Python code instead of brittle, hand-written prompt strings
  • Includes optimization algorithms for prompts and weights, backed by published research
  • Permissive MIT license with a large community (about 38.8k GitHub stars)

guidance

  • Constrained generation lets you guarantee output syntax, per the README
  • Works with several backends, including Transformers, llama.cpp, and OpenAI
  • MIT licensed with an active repository and a large star count

Not ideal for

DSPy

  • People who only need a one-off chat prompt; the framework adds structure that is unnecessary for simple use
  • Non-Python users, since the README only shows Python code and pip installation
  • Anyone wanting a no-code tool; the README describes a programming framework

guidance

  • Users who only use hosted chat interfaces and do not write Python, since it is a code library
  • Projects that need a model backend without the required backend installed, because the README says you need the backend for your model first
  • Teams needing a stable API, since the latest release is 0.3.2 and the README does not describe stability guarantees

Trade-offs

DSPy

  • The README points to external docs for most details, so the top-level README gives limited hands-on guidance
  • The README notes a recent LM integration change with breaking changes to provider options, so check the migration guide before upgrading
  • Optimization benefits depend on having a sensible evaluation metric, which the README does not explain in detail

guidance

  • You must have a supported model backend set up, which adds setup effort
  • The README notes constraint support depends on the backend LLM having full Guidance support
  • Documentation shown in the README is partial, since it is truncated

Getting started

DSPy

Install from PyPI

pip install dspy
Step-by-step guide: how to use DSPy

guidance

Install from PyPI

pip install guidance
Step-by-step guide: how to use guidance

Frequently asked questions

What is the difference between DSPy and guidance?

DSPy: A Python framework for building and optimizing language model programs instead of hand-writing prompts. guidance: A Python library for steering language models so their output follows a set structure. DSPy suits python developers building lm-based pipelines such as rag or multi-step agents, while guidance suits python developers who need model output in a predictable format, such as json-like or fixed-choice answers.

Are DSPy and guidance free?

DSPy: Free and open source. guidance: Free and open source.

Is DSPy or guidance more popular?

DSPy has more GitHub stars (38.9k) than guidance (21.8k). Popularity isn't the same as fit — check which one matches your use case above.

What are other alternatives to DSPy and guidance?

Other options people compare them with include LangChain, LlamaIndex, PromptPerfect, promptfoo, Braintrust.

Keep comparing

Built from our catalogue entries for both products: open-source details come from each project's README (AI-assisted, refreshed weekly) and GitHub data; AI-tool details are editorial. Spotted something wrong? Let us know from either product's page.