{"record":{"id":"3656361becbcf8cd","repo":"langchain-ai/deepagents","slug":"goal-criteria-request-kind-must-be-create-or-amend","errorCode":null,"errorMessage":"Goal criteria request kind must be create or amend.","messagePattern":"Goal criteria request kind must be create or amend\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/goal_rubric.py","lineNumber":1223,"sourceCode":"        (with `criteria` and `feedback` guaranteed present), otherwise a\n        `GoalCreateRequest`. Fields not valid for the resolved kind are dropped.\n\n    Raises:\n        TypeError: If the request or one of its fields has the wrong type.\n        ValueError: If a required request value is missing or invalid.\n    \"\"\"\n    if not isinstance(value, dict):\n        msg = \"Goal criteria request must be an object.\"\n        raise TypeError(msg)\n    request_id = value.get(\"request_id\")\n    kind = value.get(\"kind\")\n    objective = value.get(\"objective\")\n    if not isinstance(request_id, str) or not request_id.strip():\n        msg = \"Goal criteria request requires a request_id.\"\n        raise ValueError(msg)\n    if kind not in {\"create\", \"amend\"}:\n        msg = \"Goal criteria request kind must be create or amend.\"\n        raise ValueError(msg)\n    if not isinstance(objective, str) or not objective.strip():\n        msg = \"Goal criteria request requires an objective.\"\n        raise ValueError(msg)\n\n    # Values are validated for non-blankness but stored verbatim (not stripped):\n    # this feature deliberately preserves the user's exact goal/criteria wording,\n    # and the prompt builders wrap each value in explicit XML boundaries.\n    optional: dict[str, str] = {}\n    for key in (\"criteria\", \"feedback\", \"previous_criteria\"):\n        item = value.get(key)\n        if item is None:\n            continue\n        if not isinstance(item, str):\n            msg = f\"Goal criteria request field {key} must be text.\"\n            raise TypeError(msg)\n        optional[key] = item\n\n    if kind == \"amend\":","sourceCodeStart":1205,"sourceCodeEnd":1241,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/goal_rubric.py#L1205-L1241","documentation":"A goal-criteria request must declare whether it creates a new goal or amends an existing one. `_goal_criteria_request` validates `kind` against the closed set `{\"create\", \"amend\"}` and raises this `ValueError` for any other value.","triggerScenarios":"Supplying `kind` values such as \"update\", \"Create\", \"new\", `None`, or omitting `kind` entirely when building a goal-criteria request that reaches the `before_agent`/`abefore_agent` middleware hook.","commonSituations":"Case-sensitivity mistakes (\"Amend\" vs \"amend\"); renaming a caller-side enum without matching this vocabulary; a code path that reuses a create-request template for a different operation.","solutions":["Set `kind` to exactly \"create\" or \"amend\" (lowercase).","Normalize caller-side values with `.lower()` before constructing the request.","Update any custom builder/serializer that emits legacy kind names to the current two-value vocabulary."],"exampleFix":"// before\nrequest = {\"request_id\": rid, \"kind\": \"Update\", \"objective\": obj}\n// after\nrequest = {\"request_id\": rid, \"kind\": \"amend\", \"objective\": obj}","handlingStrategy":"validation","validationCode":"kind = value.get(\"kind\")\nif kind not in {\"create\", \"amend\"}:\n    raise ValueError(f\"kind must be 'create' or 'amend', got {kind!r}\")","typeGuard":"from typing import Literal, TypeGuard\nGoalKind = Literal[\"create\", \"amend\"]\ndef is_valid_kind(kind: object) -> TypeGuard[GoalKind]:\n    return kind in (\"create\", \"amend\")","tryCatchPattern":"try:\n    run_middleware(state)\nexcept ValueError as e:\n    if \"kind must be create or amend\" in str(e):\n        log_and_surface_to_user(e)","preventionTips":["Define a `Literal[\"create\", \"amend\"]` type or enum for kind and use it everywhere.","Normalize casing with `.lower()` at the input boundary.","Keep a single mapping from UI actions to request kinds."],"tags":["validation","valueerror","enum-mismatch"],"backgroundTag":"invalid-enum-value","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}