{"record":{"id":"7ebe8b09718a2cb4","repo":"langchain-ai/deepagents","slug":"rubricmiddleware-grader-did-not-return-a-structure","errorCode":null,"errorMessage":"RubricMiddleware grader did not return a structured_response. The grader sub-agent must use response_format=GraderResponse.","messagePattern":"RubricMiddleware grader did not return a structured_response\\. The grader sub-agent must use response_format=GraderResponse\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/middleware/rubric.py","lineNumber":1076,"sourceCode":"        self._record_grader_trace_metadata(metadata)\n        result = await grader.ainvoke(\n            self._grader_input(state, iteration, correction),\n            config=self._grader_invocation_config(metadata),\n            context=context,\n        )\n        self._record_grader_trace_metadata(\n            self._grader_trace_metadata(\n                effective_strategy=_strategy_from_result(result),\n            )\n        )\n        return self._extract_graded(result)\n\n    @staticmethod\n    def _extract_graded(result: dict[str, Any]) -> GraderResponse:\n        graded = result.get(\"structured_response\")\n        if graded is None:\n            msg = \"RubricMiddleware grader did not return a structured_response. The grader sub-agent must use response_format=GraderResponse.\"\n            raise RuntimeError(msg)\n        if not isinstance(graded, GraderResponse):\n            # `create_agent` returns whatever the grader's response_format\n            # resolves to; we expect a `GraderResponse` instance but accept\n            # a `dict` for forward-compat.\n            if isinstance(graded, dict):\n                graded = GraderResponse.model_validate(graded)\n            else:\n                msg = f\"RubricMiddleware grader returned unexpected structured_response of type {type(graded).__name__}.\"\n                raise TypeError(msg)\n        return graded\n\n    def _build_grader_payload(\n        self,\n        state: RubricState,\n        iteration: int,\n        correction: str | None = None,\n    ) -> str:\n        \"\"\"Assemble the grader's first user message.","sourceCodeStart":1058,"sourceCodeEnd":1094,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/middleware/rubric.py#L1058-L1094","documentation":"RubricMiddleware invokes a grader sub-agent created with response_format=GraderResponse and reads its result from structured_response. If the grader's result dict has no structured_response, the grader was constructed without a structured output format (or returned malformed/empty output), so the middleware raises RuntimeError instead of producing a bogus grade.","triggerScenarios":"Grader sub-agent built without response_format=GraderResponse; grader model failed to produce structured output; a custom grader callable returning a plain dict without a structured_response key.","commonSituations":"Swapping the grader model for one that ignores response_format; wiring a custom grader agent that returns text content; upgrading the library and pointing it at a hand-rolled grader that doesn't emit structured responses.","solutions":["Create the grader with create_agent(..., response_format=GraderResponse).","If using a custom grader, ensure its result dict includes structured_response as a GraderResponse (or dict matching it).","Verify the grader model supports structured output / tool-calling for the response format.","Log the raw grader result to check for empty or errored runs."],"exampleFix":"// before\ngrader = create_agent(model, tools=[...])\n// after\ngrader = create_agent(model, tools=[...], response_format=GraderResponse)","handlingStrategy":"try-catch","validationCode":"grader = create_agent(model, tools=tools, response_format=GraderResponse)\nassert grader is not None","typeGuard":"def grader_supports_structured(agent: object) -> bool:\n    return getattr(agent, \"response_format\", None) is GraderResponse or hasattr(agent, \"structured_response\")","tryCatchPattern":"try:\n    graded = middleware._extract_graded(result)\nexcept RuntimeError as e:\n    if \"structured_response\" in str(e):\n        # rebuild grader with response_format=GraderResponse and retry once\n        ...\n    else:\n        raise","preventionTips":["Always create the grader with response_format=GraderResponse.","Verify the chosen model supports structured output/tool calls.","For custom graders, ensure the result dict contains structured_response.","Log raw grader results when debugging grading failures."],"tags":["python","rubric","structured-output","runtime-error"],"backgroundTag":"missing-structured-response","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}