{"record":{"id":"502ed860f9c8c0bd","repo":"HKUDS/DeepTutor","slug":"graphrag-model-output-truncated","errorCode":"graphrag_model_output_truncated","errorMessage":"GraphRAG compatibility could not be verified because the model response reached its output token limit. Try again.","messagePattern":"GraphRAG compatibility could not be verified because the model response reached its output token limit\\. Try again\\.","errorType":"exception","errorClass":"GraphRagStructuredOutputTruncatedError","httpStatus":null,"severity":"error","filePath":"deeptutor/services/rag/pipelines/graphrag/completion_adapter.py","lineNumber":127,"sourceCode":"    fallback = dict(kwargs)\n    fallback[\"messages\"] = _messages_with_schema(fallback[\"messages\"], response_format)\n    fallback.pop(\"response_format\", None)\n    return fallback\n\n\ndef _format_response(response: Any, response_format: type[BaseModel]) -> Any:\n    from graphrag_llm.utils import structure_completion_response\n\n    try:\n        response.formatted_response = structure_completion_response(\n            response.content,\n            response_format,\n        )\n    except (json.JSONDecodeError, TypeError, ValidationError, ValueError) as error:\n        choices = getattr(response, \"choices\", None)\n        finish_reason = getattr(choices[0], \"finish_reason\", None) if choices else None\n        if finish_reason in {\"length\", \"max_tokens\"}:\n            raise GraphRagStructuredOutputTruncatedError(MODEL_OUTPUT_TRUNCATED_MESSAGE) from error\n        raise GraphRagStructuredOutputError(MODEL_INCOMPATIBLE_MESSAGE) from error\n    return response\n\n\ndef _native_validation_error(error: BaseException) -> bool:\n    return isinstance(error, (json.JSONDecodeError, ValidationError))\n\n\ndef _fallback_sync(instance: Any, kwargs: dict[str, Any], response_format: type[BaseModel]) -> Any:\n    fallback = _format_fallback_kwargs(kwargs, response_format)\n    if fallback.get(\"stream\"):\n        raise ValueError(\"response_format is not supported for streaming completions.\")\n    messages = fallback.pop(\"messages\")\n    if isinstance(messages, str):\n        messages = [{\"role\": \"user\", \"content\": messages}]\n    request_metrics = fallback.pop(\"metrics\", None) or {}\n    if not instance._track_metrics:\n        request_metrics = None","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/services/rag/pipelines/graphrag/completion_adapter.py#L109-L145","documentation":"GraphRagStructuredOutputTruncatedError (code graphrag_model_output_truncated): the model's response to a structured-output request failed JSON/pydantic validation AND finish_reason was 'length' or 'max_tokens', meaning the JSON was cut off by the output token limit. Raised from _format_response in the GraphRAG completion adapter.","triggerScenarios":"A chat model with a small max_tokens setting answers a GraphRAG structured request (entity extraction, probe completion) and the valid JSON gets truncated; long documents producing large extraction payloads; fallback (non-native response_format) parsing path.","commonSituations":"Provider profiles with low max_output_tokens defaults; reasoning models burning tokens on hidden reasoning before emitting JSON; local/self-hosted models with tiny context output caps.","solutions":["Raise max_tokens / output token limit for the chat model profile used by GraphRAG.","Switch to a model with larger output capacity or shorter JSON output (smaller chunk size).","Retry — the message itself says transient truncation can succeed on re-run.","Use a model that supports native response_format/structured outputs so the fallback path isn't used."],"exampleFix":"# before\nllm_cfg.max_tokens = 512\n# after\nllm_cfg.max_tokens = 4096","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = await build(root)\nexcept GraphRagStructuredOutputTruncatedError:\n    raise RetryableError(\"raise max_tokens, then retry\") from None","preventionTips":["Set generous max_tokens on models used for GraphRAG.","Run the completion probe before starting a long indexing job."],"tags":["graphrag","structured-output","token-limit","llm"],"backgroundTag":"llm-output-token-limit-exceeded","analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}