Skip to content

Cheatsheet

A one-page index of the dspy4s surface. Each row links to the page that covers it in full. For runnable versions of every construct below, see Cheatsheet.scala in the examples module.

Declare a task

I want to Use Page
Declare inputs and outputs Signature.fromType / Signature.fromString Signatures
Use named fields, enums, custom types Spec trait + Signature.of[T] Signatures

Run a task

I want to Use Page
Answer directly Predict Modules
Reason first ChainOfThought Modules
Call tools in a loop ReAct Tools & ReAct
Sample and keep the best BestOfN / Refine Modules
Chain steps into one program DynamicModule Composing programs

Talk to a model

I want to Use Page
Configure a model OpenAiLanguageModel Configuring an LM
Pick text vs JSON output ChatAdapter / JSONAdapter Adapters
Cache or track usage ManagedLanguageModel, UsageTracking Caching & usage

Measure and improve

I want to Use Page
Build labeled data Example, withInputs Examples & data
Score outputs FunctionMetric, SemanticF1 Metrics
Run a batch evaluation Evaluate Running evaluations
Improve demonstrations BootstrapFewShot, KNNFewShot Few-shot
Improve instructions COPRO, MIPROv2, GEPA Instructions

Operate

I want to Use Page
Configure the active model/adapter RuntimeContext, RuntimeEnvironment Runtime context
Observe a run CallbackHandler, inspectHistory Observability
Persist a tuned program ProgramPersistence Saving & loading
Stream output Streamify, StreamListener Streaming