Joint instruction and few-shot optimization using grounded proposals and categorical TPE.
The implementation follows DSPy MIPROv2's three stages: metric-filtered demonstration bootstrapping, predictor-specific grounded instruction proposal, and seeded multivariate Bayesian search. Minibatch trials inform the surrogate, but only full validation evaluations can select the returned program.
:init_temperature is the pinned DSPy proposal-temperature control.
:proposal_response_format optionally binds each proposal to Imp's strict
one-instruction JSON schema (:off, :auto, or :required).
Program-aware proposals use structural program metadata by default. Source
text is included only through the explicit program_grounding: :module_source
or program_grounding: {:text, context} opt-in.
:proposer_fidelity defaults to Imp's :beam_native grounded proposer. Set
it to :dspy_3_2_1 to use DSPy's pinned data- and tip-aware proposal flow.
Program awareness requires explicit text grounding and
performs DSPy's program-description and module-description calls before each
candidate; few-shot awareness uses the same ordered demo arms searched by the
optimizer. Both zero-shot and joint instruction/demonstration search are
supported; unsupported proposer combinations fail before any LM call.
Pinned dataset grounding renders the JSON-safe values in Imp.Example with
DSPy/Python spelling. Use Jason.OrderedObject when nested JSON object order
is semantically significant; unsupported values fail before proposer
transport with their exact example path.
:search_fidelity separately controls parameter search. The startup-only
:dspy_3_2_1_optuna_4_9_0_startup mode reproduces Optuna 4.9.0's NumPy
RandomState startup sequence exactly and rejects configurations that would
enter modeled TPE. :dspy_3_2_1_optuna_4_9_0 continues through Optuna's
multivariate categorical TPE phase with the pinned split, Parzen kernels,
candidate sampling, and independent NumPy RNG streams. The default
categorical Parzen search is BEAM-native and produces its own deterministic
sequence for a given seed.
An explicit compile-time seed: 0 is a real seed in the default BEAM-native
mode. The pinned :dspy_3_2_1 proposer mode deliberately mirrors DSPy's
Python-truthiness behavior and retains the constructor seed when the compile
override is zero.
Checkpoints
Pass these to Imp.optimize/5. :max_trials limits the number of new
objective trials executed by one invocation. :checkpoint_fn receives a
JSON-safe checkpoint after setup and after each completed trial. Pass any
emitted checkpoint back as :resume_state to continue without replaying
setup or completed trials. Checkpoints are trial-atomic, so an interrupted
in-flight trial is retried.
Summary
Functions
Returns a typed fail-closed error for an operational guard inside an LM or program callback.
Raises the typed operational guard error outside normalized call boundaries.
Functions
Returns a typed fail-closed error for an operational guard inside an LM or program callback.
Generic Imp call boundaries intentionally normalize raised exceptions. A route, cost, transport, budget, or cancellation guard that runs inside those boundaries must therefore return this tuple so pinned MIPRO search can distinguish it from an ordinary task/adapter failure:
MIPROv2.operational_error(:cost, :nonzero_provider_cost,
message: "provider cost guard drift"
)Use operational_error!/3 only outside a normalized LM/program callback.
Raises the typed operational guard error outside normalized call boundaries.