langchain-ai/deepagents · error · ValueError

RubricMiddleware: `model` is required.

Error message

RubricMiddleware: `model` is required.

What it means

RubricMiddleware requires a `model` (the LLM used to grade against the rubric). An empty/None/falsy model raises ValueError in `__init__` because the middleware cannot perform evaluations without one.

Source

Thrown at libs/deepagents/deepagents/middleware/rubric.py:572

    state_schema = RubricState

    def __init__(  # noqa: D107
        self,
        *,
        model: str | BaseChatModel,
        system_prompt: str | None = None,
        tools: Sequence[BaseTool] | None = None,
        grader_middleware: Sequence[AgentMiddleware[Any, Any, Any]] | None = None,
        grader_context_schema: type[Any] | None = None,
        grader_state_schema: type[AgentState[Any]] | None = None,
        prepare_messages_for_grader: Callable[[list[AnyMessage]], list[AnyMessage]] | None = None,
        build_grader_state: Callable[[RubricState, int], Mapping[str, Any]] | None = None,
        max_iterations: int = 3,
        on_evaluation: Callable[[RubricEvaluation], None] | None = None,
    ) -> None:
        if not model:
            msg = "RubricMiddleware: `model` is required."
            raise ValueError(msg)
        if not isinstance(max_iterations, int) or isinstance(max_iterations, bool):
            msg = f"RubricMiddleware: `max_iterations` must be an int, got {type(max_iterations).__name__}."
            raise TypeError(msg)
        if max_iterations < 1:
            msg = f"RubricMiddleware: `max_iterations` must be positive, got {max_iterations}."
            raise ValueError(msg)
        if grader_state_schema is None and build_grader_state is not None:
            msg = "RubricMiddleware: `grader_state_schema` is required with `build_grader_state`."
            raise ValueError(msg)
        for name, callback in (
            ("prepare_messages_for_grader", prepare_messages_for_grader),
            ("build_grader_state", build_grader_state),
        ):
            if callback is not None and not callable(callback):
                msg = f"RubricMiddleware: `{name}` must be callable."
                raise TypeError(msg)

        self.max_iterations = max_iterations

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Pass a model instance or model string, e.g. RubricMiddleware(model="openai:gpt-4o") or init_chat_model(...)
  2. Check that the config/env providing the model is actually set and non-empty
  3. Fail fast earlier in your setup code if no model is configured

Example fix

// before
mw = RubricMiddleware(rubric=my_rubric)  # model missing
// after
mw = RubricMiddleware(rubric=my_rubric, model="openai:gpt-4o")
Defensive patterns

Strategy: validation

Validate before calling

def build_rubric_middleware(**kw):
    if not kw.get("model"):
        raise ValueError("RubricMiddleware: `model` is required.")
    return RubricMiddleware(**kw)

Type guard

def has_model(cfg) -> bool:
    return bool(cfg.get("model"))

Try / catch

try:
    mw = RubricMiddleware(rubric=rubric, model=model)
except ValueError as e:
    if "model` is required" in str(e):
        model = default_model()  # e.g. init_chat_model("openai:gpt-4o")
        mw = RubricMiddleware(rubric=rubric, model=model)
    else:
        raise

Prevention

When it happens

Trigger: RubricMiddleware(model=None), RubricMiddleware(model="") or omitting the model argument entirely.

Common situations: Model loaded conditionally from env/config that resolved to None (missing API key path), or refactoring that dropped the model parameter.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/ee9178d834515035. Report an issue: GitHub.