Skip to content

Deepeval Dm Wrapper

Adapter that lets DeepEval's native system_one metrics be judged by SDK decision-model invokers.

DeepEval prepares typed questions and computes the metric score itself. This module converts those questions for a BaseDMInvoker, validates and converts the answers back without rescaling, clipping or filling any value, and runs the decision-model fallback chain with per-model usage and the winning judge. It also holds the small helpers that the native metric lifecycle shares: explicit judge bindings, overflow classification and media handling.

DeepEvalDMWrapper(dm, fallback_dms=None)

Bases: UsageRecordingMixin, DeepEvalBaseSystemOneModel

Adapt SDK decision-model invokers to DeepEval's native questions.

Attributes:

Name Type Description
winning_invoker BaseDMInvoker | None

The invoker that answered the latest request, or None before a success.

max_state_tokens int

State-plus-longest-question budget, in DeepEval's estimated tokens.

max_request_tokens int

Whole-request budget, in DeepEval's estimated tokens.

Initialize a decision-model-only chain without creating a provider client.

Parameters:

Name Type Description Default
dm BaseDMInvoker

The primary decision-model invoker.

required
fallback_dms list[BaseDMInvoker] | None

Invokers tried in order after the primary fails. Defaults to None.

None

a_decide(state, questions) async

Answer one native request through the decision-model fallback chain.

Parameters:

Name Type Description Default
state Any

The row data DeepEval prepared, passed to the invoker unchanged.

required
questions dict[str, SystemOneQuestion]

DeepEval's typed judge questions.

required

Returns:

Type Description
tuple[SystemOneAnswers, None]

tuple[SystemOneAnswers, None]: The validated answers and no price. Empty answers when no question is supplied, without a provider call.

Raises:

Type Description
SystemOneContextLimitError

If the request exceeds the local context budget.

EvalConfigurationError

If a question definition is unsupported, before any provider call.

EvalJudgeResponseError

If the only judge returned an unusable answer.

EvalJudgesExhaustedError

If several judges failed in different ways.

decide(state, questions)

Reject synchronous execution.

Parameters:

Name Type Description Default
state Any

Ignored.

required
questions dict[str, SystemOneQuestion]

Ignored.

required

Raises:

Type Description
EvalUnsupportedSyncOperationError

Always.

get_model_name(*args, **kwargs)

Return the winner's model ID, or the primary's before a success.

Parameters:

Name Type Description Default
*args Any

Ignored.

()
**kwargs Any

Ignored.

{}

Returns:

Name Type Description
str str

The model ID.

load_model(*args, **kwargs)

Leave model loading to the configured SDK invokers.

Parameters:

Name Type Description Default
*args Any

Ignored.

()
**kwargs Any

Ignored.

{}

Returns:

Name Type Description
None None

There is no DeepEval-side model object.

as_context_overflow(error)

Express a local overflow as the provider overflow type, so the chain policy treats it as a judge failure.

The message is fixed and carries no text from the local error, which stays available as the cause.

Parameters:

Name Type Description Default
error BaseException

The local overflow, or the DeepEvalError that wraps it.

required

Returns:

Name Type Description
ContextOverflowError ContextOverflowError

A new error chained from error.

is_all_context_overflow(error)

Return whether every judge failure in a chain was a context overflow.

Matches types only, never message text.

Parameters:

Name Type Description Default
error BaseException

The error that ended the judge chain.

required

Returns:

Name Type Description
bool bool

True for a direct ContextOverflowError, or an EvalJudgesExhaustedError with children that are all ContextOverflowError.

is_local_context_overflow(error)

Return whether an error is DeepEval's local context-budget failure.

Matches types only: the error itself, or the cause of a DeepEvalError that DeepEval's runner wrapped it in.

Parameters:

Name Type Description Default
error BaseException

The error caught at the measurement boundary.

required

Returns:

Name Type Description
bool bool

True if the error is or was caused by a SystemOneContextLimitError.

lm_accepts_media(metric_name, wrapper) async

Return whether an LM judge can accept a row that references media.

Parameters:

Name Type Description Default
metric_name str

The metric's name, for the capability error.

required
wrapper DeepEvalLLMWrapper

The wrapper holding the LM judge to probe.

required

Returns:

Name Type Description
bool bool

False when the judge cannot be confirmed to accept images, otherwise True.

Raises:

Type Description
BaseError

The judge's own failure when the capability probe fails for an operational reason.

native_judge_kwargs(judge)

Build explicit DeepEval constructor bindings for the selected judge.

Explicit bindings keep ambient DeepEval settings from changing the judge family.

Parameters:

Name Type Description Default
judge DeepEvalLLMWrapper | DeepEvalDMWrapper

The wrapper that will judge the row.

required

Returns:

Type Description
dict[str, Any]

dict[str, Any]: Keyword arguments for the DeepEval metric constructor.

no_media_judge_message(metric_name, media_skips, *, uncertain_skip=False)

Build the error for a media row that every judge skipped.

A provider's rejection of the image probe is quoted, and the retry hint is given only when a skip may come from a check that failed transiently.

Parameters:

Name Type Description Default
metric_name str

The metric's name.

required
media_skips list[str]

Model IDs of the judges skipped for media, in chain order.

required
uncertain_skip bool

Whether any skip may come from a check that failed transiently. Defaults to False.

False

Returns:

Name Type Description
str str

The error message for a row that no judge could take.

run_mixed_chain(metric_name, judges, skip_dm_for_media, attempt, *, media_error_message=None) async

Try each judge of a mixed LM and decision-model chain once, in order, and return the first usable result.

Any judge that cannot take the row's media signals a skip by returning None from attempt; when skip_dm_for_media is True, decision models are skipped without calling attempt. After a local context overflow, the remaining decision models are recorded as overflowed without a call, because the SDK budget applies to every one of them.

Parameters:

Name Type Description Default
metric_name str

The metric's name, for the media error.

required
judges list[BaseLMInvoker | BaseDMInvoker]

The chain, primary first.

required
skip_dm_for_media bool

Whether to skip decision models before calling attempt because the row references media that decision models cannot take.

required
attempt Callable[[BaseLMInvoker | BaseDMInvoker], Awaitable[_T | None]]

Runs one complete measurement with one judge. Returns None when that judge cannot take the row's media.

required
media_error_message Callable[[list[str]], str] | None

Custom builder for the all-skipped media error message. Defaults to None, which uses no_media_judge_message.

None

Returns:

Type Description
tuple[BaseLMInvoker | BaseDMInvoker, _T]

tuple[BaseLMInvoker | BaseDMInvoker, _T]: The judge that succeeded and its attempt's result.

Raises:

Type Description
EvalUnsupportedOperationError

If the row references media and every judge was skipped for it.

EvalInputError

If every attempt overflowed its context and a decision model was among them.

BaseError

The single failed judge's own error, or a failure that no other judge can fix.

EvalJudgesExhaustedError

If two or more judges failed in different ways.