langchain-ai/deepagents · error · ValueError

Goal criteria request requires an objective.

Error message

Goal criteria request requires an objective.

What it means

Every goal-criteria request carries the goal `objective`, which must be a non-blank string since it becomes the persisted goal text. `_goal_criteria_request` raises this `ValueError` when `objective` is missing, not a string, or only whitespace. Values are stored verbatim (not stripped) to preserve the user's exact wording.

Source

Thrown at libs/code/deepagents_code/goal_rubric.py:1226

    Raises:
        TypeError: If the request or one of its fields has the wrong type.
        ValueError: If a required request value is missing or invalid.
    """
    if not isinstance(value, dict):
        msg = "Goal criteria request must be an object."
        raise TypeError(msg)
    request_id = value.get("request_id")
    kind = value.get("kind")
    objective = value.get("objective")
    if not isinstance(request_id, str) or not request_id.strip():
        msg = "Goal criteria request requires a request_id."
        raise ValueError(msg)
    if kind not in {"create", "amend"}:
        msg = "Goal criteria request kind must be create or amend."
        raise ValueError(msg)
    if not isinstance(objective, str) or not objective.strip():
        msg = "Goal criteria request requires an objective."
        raise ValueError(msg)

    # Values are validated for non-blankness but stored verbatim (not stripped):
    # this feature deliberately preserves the user's exact goal/criteria wording,
    # and the prompt builders wrap each value in explicit XML boundaries.
    optional: dict[str, str] = {}
    for key in ("criteria", "feedback", "previous_criteria"):
        item = value.get(key)
        if item is None:
            continue
        if not isinstance(item, str):
            msg = f"Goal criteria request field {key} must be text."
            raise TypeError(msg)
        optional[key] = item

    if kind == "amend":
        criteria = optional.get("criteria", "")
        feedback = optional.get("feedback", "")
        if not criteria.strip() or not feedback.strip():

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Provide a non-empty string in the `objective` field of the request.
  2. For amend requests, re-send the current objective if the caller doesn't change it.
  3. Reject blank user input at the UI/form layer before constructing the request.

Example fix

// before
request = {"request_id": rid, "kind": "create", "objective": "   "}
// after
request = {"request_id": rid, "kind": "create", "objective": "Automate release notes generation"}
Defensive patterns

Strategy: validation

Validate before calling

objective = value.get("objective")
if not isinstance(objective, str) or not objective.strip():
    raise ValueError("objective must be a non-blank string")

Type guard

def has_valid_objective(value: dict) -> bool:
    obj = value.get("objective")
    return isinstance(obj, str) and bool(obj.strip())

Try / catch

try:
    run_middleware(state)
except ValueError as e:
    if "requires an objective" in str(e):
        prompt_user_for_objective()

Prevention

When it happens

Trigger: Dispatching a goal-criteria request where `objective` is absent, `None`, an empty string, whitespace-only, or a non-string (list, dict, number) via the middleware's `before_agent`/`abefore_agent` entry points.

Common situations: A UI flow that submits an amend request without the user retyping the objective; templated requests with the objective left as a placeholder; form input that wasn't trimmed and was pure whitespace.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


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