Skip to content

dspy.configure

Set the default language model, adapter, and other settings for DSPy.

dspy.configure(**kwargs)

Call dspy.configure(...) once near the top of your script or notebook. Every DSPy module will use these defaults unless you override them with dspy.context. The values persist until you call dspy.configure(...) again.

Note

Pass a dspy.LM object as lm, not a bare model string.

Settings

Setting Default Description
lm None Default language model. Pass a dspy.LM instance.
adapter None Formats prompts and parses LM responses. When None, modules use dspy.ChatAdapter.
callbacks [] Observability and logging hooks. See Observability.
track_usage False Record token counts for every LM call.
async_max_workers 8 Maximum concurrent workers for async operations.
num_threads 8 Thread count for dspy.Parallel.
max_errors 10 Stop parallel execution after this many errors.
disable_history False Stop recording LM call history.
max_history_size 10000 Cap on stored history entries.
allow_tool_async_sync_conversion False Let async tools run in synchronous code. See Async.
provide_traceback False Include Python tracebacks in error logs.
warn_on_type_mismatch True Warn when a module input type does not match the signature.

Examples

Set the default LM

import dspy

dspy.configure(lm=dspy.LM("openai/gpt-5-mini"))

qa = dspy.Predict("question -> answer")
result = qa(question="What is the capital of France?")
print(result.answer)

Set the LM and adapter

import dspy

dspy.configure(
    lm=dspy.LM("anthropic/claude-sonnet-4-6"),
    adapter=dspy.JSONAdapter(),
)

Enable usage tracking and tune concurrency

import dspy

dspy.configure(
    lm=dspy.LM("gemini/gemini-3-flash-preview"),
    track_usage=True,
    async_max_workers=4,
)

When to use dspy.configure

Use dspy.configure(...) when one set of defaults should apply to most of your program—scripts, notebooks, test setup, or application startup.

If you need different settings for one call or one block, use dspy.context instead.

Thread safety

Only the thread that first calls dspy.configure(...) may call it again. Other threads that try will get a RuntimeError. In async code, only the task that first called dspy.configure(...) may continue to call it.

For temporary overrides inside worker threads, async tasks, or dspy.Parallel blocks, use dspy.context.

See Also

  • dspy.context — temporary overrides that last for one block.
  • dspy.LM — create the language model you pass as lm.
  • Language Models — overview of LM configuration.
  • Adapters — how adapters format prompts and parse responses.