[Bug]: create_community_reports fails on strict/flat-schema guided-JSON backends (nested response_format)
维护者通常 5 天内回复
还没有人认领这个 Issue。
评估
调研方向
Look at the CommunityReportsExtractor in the codebase, likely in a file like community_reports.py or extractors/. The bug is in how response_format is passed to LLMCompletion.completion_async. The fix involves removing the nested Pydantic model from the response_format, parsing the JSON response manually, and validating it with CommunityReportResponse. Check the existing tests in tests/verbs/test_create_community_reports.py to understand the expected behavior and ensure the fix doesn't break them.
由索引模型根据 Issue 内容生成。
描述
Do you need to file an issue?
- I have searched the existing issues and this bug is not already filed.
- My model is not hosted on OpenAI or Azure — see note below on why this isn't a "model providers" question.
- I believe this is a legitimate bug, not just a question.
Note on the "model providers" checkbox: I'm reproducing this against a
Databricks AI Gateway (serving an open-weights model), but the root cause
is not provider-specific — it's howCommunityReportsExtractorbuilds its
response_format. Any backend that enforces strict/flat JSON Schema
guided decoding (vLLM guided decoding,outlines,lm-format-enforcer
servers, etc.) will hit the exact same failure, because the bug is in how
the Pydantic schema forCommunityReportResponsegets generated on the
client side, not in anything provider-specific.
Describe the bug
CommunityReportsExtractor.__call__ passes
response_format=CommunityReportResponse to LLMCompletion.completion_async,
where CommunityReportResponse.findings is typed as list[FindingModel] —
a nested Pydantic BaseModel.
Pydantic's model_json_schema() (and litellm's type_to_response_format_param,
which builds the actual {"type": "json_schema", ...} wire payload from it)
always factors a nested BaseModel out into a top-level $defs entry
referenced via $ref. There is no built-in option to force full inlining.
A number of OpenAI-"strict"-mode-compatible guided-JSON backends only
implement the flat subset of JSON Schema and reject any schema containing
$defs/$ref outright. Concretely, I hit this against a Databricks AI
Gateway serving an open-weights model (gpt-oss-20b):
litellm.BadRequestError: DatabricksException - {"error_code":"BAD_REQUEST","message":"Invalid JSON schema - /$defs/FindingModel\n"}
The same class of guided-decoding backend (vLLM's guided decoding,
outlines, lm-format-enforcer-based servers) is known to have the same
restriction, so this isn't Databricks-specific.
Impact: every single call to create_community_reports fails with this
error on any such backend. summarize_communities catches the exception
per-community (No report found for community: N), so the workflow doesn't
crash immediately and indexing keeps going with a misleading Pipeline complete — the run only reports the failure at the very end, when
finalize_community_reports tries to pandas.merge the (empty) reports
frame on a community column that was never produced, and raises
KeyError: 'community'.
Suggested fix (already implemented and validated on my side, see
"Logs and screenshots" below): since the prompt already asks for the JSON
shape in prose, stop relying on server-side structured-output enforcement
for this one call and instead parse + validate the response text on the
client — drop response_format=CommunityReportResponse from the
completion_async(...) call, add a small _parse_json_response(content: str) -> dict helper that json.loadss the raw text (tolerating a wrapping
```json fence and leading/trailing prose via a fallback slice between
the first { and last }), and construct
CommunityReportResponse(**_parse_json_response(response.content))
directly. No public API changes: CommunityReportsResult,
CommunityReportResponse, and FindingModel are unchanged.
Pull request creation on this repo currently appears restricted to
collaborators, so I can't open a PR directly — happy to submit one (or
paste the diff here) if a maintainer can enable that, or if someone with
write access wants to apply it.
Steps to reproduce
- Configure
graphragto use a completion backend that enforces strict/flat
JSON Schema guided decoding (e.g. a Databricks AI Gateway serving an
open-weights model, or a self-hosted vLLM server with guided decoding). - Run
graphrag indexon any corpus that reaches thecreate_community_reports
workflow step. - Observe every community report call fail with something like:
litellm.BadRequestError: ... Invalid JSON schema - /$defs/FindingModel - The run still ends with a misleading
Pipeline complete; the real
failure only surfaces asKeyError: 'community'from
finalize_community_reports.
Minimal repro isolating the variable (no graphrag needed):
from pydantic import BaseModel
import litellm
class Finding(BaseModel):
summary: str
explanation: str
class FlatReport(BaseModel):
title: str
summary: str
rating: float
class NestedReport(BaseModel):
title: str
summary: str
findings: list[Finding]
rating: float
litellm.completion(..., response_format=FlatReport) # succeeds
litellm.completion(..., response_format=NestedReport) # BadRequestError: Invalid JSON schema - /$defs/Finding
Expected Behavior
create_community_reports should succeed on any OpenAI-compatible backend
whose completion model can follow the prompt's JSON instructions, regardless
of whether that backend supports server-side schemas containing $defs/$ref.
GraphRAG Config Used
# Not config-specific -- reproducible with any completion_models backend
# that enforces strict/flat JSON Schema guided decoding. In my case:
completion_models:
default_completion_model:
type: litellm
model_provider: databricks
model: databricks/gpt-oss-20b # served via a Databricks AI Gateway
Logs and screenshots
Before the fix, against a real ~1.1MB / 32-document corpus:
litellm.BadRequestError: DatabricksException - {"error_code":"BAD_REQUEST","message":"Invalid JSON schema - /$defs/FindingModel\n"}
0 / 357 communities got a report (100% failure); the run ends in a
misleading "Pipeline complete", with the real failure only surfacing as:
KeyError: 'community'
from finalize_community_reports's pandas.merge on the (empty) reports
frame.
After the fix described above: 350 / 357 communities got a report (98%);
the remaining ~2% failed for unrelated, expected reasons (a transient rate
limit and one case of genuinely malformed JSON from the model), not the
schema bug. tests/verbs/test_create_community_reports.py (mocked
completion path) also still passes after the change.
Additional Information
- GraphRAG Version: current
main(post uv-workspace monorepo restructure) - Operating System: Linux (Databricks Gateway backend), reproduced logic
verified on Windows too - Python Version: 3.12
- Related Issues:
- 主要语言
- Python
- 星标
- 36.6k
- 派生
- 3.9k
- 平均合并
- 4 天 11 小时
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/graphrag 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
microsoft/graphrag#2626 · 1 条评论 ·
维护者通常 5 天内回复
-
[Bug]: response_format_json_object=True is silently dropped, so JSON mode never reaches the model未关闭bug triage
难度 2/5 1-3 小时 新手友好度 72/100
microsoft/graphrag#2625 · 1 条评论 ·
维护者通常 5 天内回复
-
难度 1/5 1 小时以内 新手友好度 95/100
维护者通常 5 天内回复
-
[Bug]: JsonCache.get() crashes with unhandled AttributeError on non-dict or invalid envelope JSON payloads可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
microsoft/graphrag#2614 · 2 条评论 ·
维护者通常 5 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
microsoft/graphrag#2594 · 1 条评论 ·
维护者通常 5 天内回复
查看 microsoft/graphrag 的全部 Issue
相似的 Issue
-
documentation good first issue
难度 2/5 1-3 小时 新手友好度 88/100
JheysonJhordyHuarauyaRiquelme/sprocguard#18 ·
维护者通常 1 天内回复
-
enhancement good first issue help wanted
难度 2/5 1-3 小时 新手友好度 80/100
dlq/synthpopcan#59 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
mdn/translated-content#40220 ·
维护者通常 4 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 84/100
ETSInitiative/PETSIRD#243 ·
维护者通常 1 天内回复
-
deferred p2
难度 2/5 1-3 小时 新手友好度 70/100
cuadrao-ai/argus#2160 ·
维护者通常 1 天内回复