Skip to content

dspy4s

A Scala 3 library for building language model programs with signatures. Inputs and outputs are ordinary Scala types, so the compiler checks them for you.

// A signature declares inputs and outputs.
val classify = Predict(Signature.fromType[(sentence: String) => (sentiment: Boolean)])

classify.apply((sentence = "it's a charming and often affecting journey.")).map(_.output.sentiment)
// Either[DspyError, Boolean]

Why dspy4s

  • Typed signatures


    Signatures are ordinary Scala types. Inputs and outputs are named tuples, so you get dot-access (_.output.sentiment) and a compile error when a field is wrong, instead of a runtime lookup failure.

    Signatures

  • Composable modules


    Build programs from Predict, ChainOfThought, and ReAct, then compose them like any other Scala value.

  • Compiler-verified docs


    Every code sample on this site is extracted from a module that builds under strict flags (-Werror, -Wunused:all). A snippet that would not compile fails the build, so the docs stay correct.

  • Optimizers


    Bootstrap few-shot, COPRO, MIPROv2, and a self-contained GEPA implementation for optimizing prompts and few-shot demonstrations.

Early days

dspy4s is a work in progress and not yet published to Maven Central. See Installation for how to build from source.