[Bug]: create_community_reports fails on strict/flat-schema guided-JSON backends (nested response_format)
Los mantenedores suelen responder en 5 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 65/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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:
- Lenguaje dominante
- Python
- Estrellas
- 36.6k
- Forks
- 3.9k
- Merge medio
- 4 d 11 h
- PR fusionados (30 d)
- 1
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/graphrag
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
microsoft/graphrag#2626 · 1 comentario ·
Los mantenedores suelen responder en 5 días
-
[Bug]: response_format_json_object=True is silently dropped, so JSON mode never reaches the modelAbiertobug triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
microsoft/graphrag#2625 · 1 comentario ·
Los mantenedores suelen responder en 5 días
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
Los mantenedores suelen responder en 5 días
-
[Bug]: JsonCache.get() crashes with unhandled AttributeError on non-dict or invalid envelope JSON payloadsQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
microsoft/graphrag#2614 · 2 comentarios ·
Los mantenedores suelen responder en 5 días
-
[Bug]: JSONLinesFileReader drops rows containing U+2028, U+2029 or U+0085 (uses str.splitlines)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
microsoft/graphrag#2594 · 1 comentario ·
Los mantenedores suelen responder en 5 días
Todos los issues de microsoft/graphrag
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
deepchem/deepchem#5289 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Pull Request for pretty_macAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 60/100
UKGovernmentBEIS/inspect_evals#2892 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Versioning docs: say that no output from the 0.46 warning check means nothing is affectedPosiblemente ocupada @grelinfo la tomó hoy. Abiertodocumentation priority:low size:S
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
alphacrack/readme2demo#293 ·