Graphify-Labs/graphify · error · ValueError
graph file {path} is {size:_d} bytes, exceeds {cap:_d}-byte
Error message
graph file {path} is {size:_d} bytes, exceeds {cap:_d}-byte cap
(set GRAPHIFY_MAX_GRAPH_BYTES=<bytes> or GRAPHIFY_MAX_GRAPH_BYTES=<N>GB to raise the limit) What it means
Raised by check_graph_file_size_cap in graphify/security.py when a graph file's on-disk size exceeds the configured cap (from GRAPHIFY_MAX_GRAPH_BYTES, parsed per call so the env var can be set any time). It fires before the file is read and JSON-parsed, protecting callers from memory-bomb graph.json files measured in GiB. stat() failures are deliberately ignored so the caller's own existence check surfaces the clearer error.
Source
Thrown at graphify/security.py:379
graph.json is read into memory and JSON-parsed. Silently returns when
``path.stat()`` cannot be read — the caller's own existence/path check
is expected to surface a clearer error in that case.
The cap is resolved on every call via :func:`_max_graph_file_bytes`, so the
``GRAPHIFY_MAX_GRAPH_BYTES`` env var can be set before import and still
apply.
Raises:
ValueError - file size exceeds the cap. The message includes the
observed size, the cap, and how to raise the limit.
"""
cap = _max_graph_file_bytes()
try:
size = path.stat().st_size
except OSError:
return
if size > cap:
raise ValueError(
f"graph file {path} is {size:_d} bytes, exceeds {cap:_d}-byte cap\n"
f"(set GRAPHIFY_MAX_GRAPH_BYTES=<bytes> or "
f"GRAPHIFY_MAX_GRAPH_BYTES=<N>GB to raise the limit)"
)
# ---------------------------------------------------------------------------
# Label sanitisation (mirrors code-review-graph's _sanitize_name pattern)
# ---------------------------------------------------------------------------
_CONTROL_CHAR_RE = re.compile(r"[\x00-\x1f\x7f]")
_MAX_LABEL_LEN = 256
def sanitize_label(text: str | None) -> str:
"""Strip control characters and cap length.
Safe for embedding in JSON data (inside <script> tags) and plain text.View on GitHub (pinned to 7fe58b0b0f)
Solutions
- Raise the cap if you trust the file: export GRAPHIFY_MAX_GRAPH_BYTES=<bytes> (or <N>GB form) exactly as the message suggests.
- Rebuild the graph with a smaller scope (subset of the repo) to shrink graph.json below the default cap.
- Check the actual size (ls -l graphify-out/graph.json) to confirm the file is legitimate and not corrupted or accidentally duplicated.
- Ensure machines loading the graph have enough RAM for a JSON document of that size before raising the limit.
Example fix
# before
graph = _load_graph("graphify-out/graph.json") # ValueError: exceeds cap
# after
import os
os.environ["GRAPHIFY_MAX_GRAPH_BYTES"] = "2GB" # or e.g. "2147483648"
graph = _load_graph("graphify-out/graph.json") Defensive patterns
Strategy: validation
Validate before calling
def graph_within_cap(path: Path, cap: int) -> bool:
try:
return path.stat().st_size <= cap
except OSError:
return False
# mirror of the default limit resolution
def default_cap() -> int:
raw = os.environ.get("GRAPHIFY_MAX_GRAPH_BYTES", "").strip().upper()
if raw.endswith("GB"):
return int(float(raw[:-2]) * 1024**3)
return int(raw) if raw else 1 * 1024**3 # confirm default from docs before relying Type guard
def is_loadable_graph_size(path: Path) -> bool:
return graph_within_cap(path, default_cap()) Try / catch
try:
G = _load_graph(path)
except ValueError as e:
if "exceeds" in str(e) and "cap" in str(e):
size = Path(path).stat().st_size
if size < 2 * 1024**3 and psutil.virtual_memory().available > 4 * size:
os.environ["GRAPHIFY_MAX_GRAPH_BYTES"] = f"{size + 1}"
G = _load_graph(path)
else:
raise
else:
raise Prevention
- Set GRAPHIFY_MAX_GRAPH_BYTES deliberately per environment instead of discovering the cap at load time.
- Check file size before loading in scripts that consume arbitrary graphs.
- Keep graph builds scoped so graph.json stays well under the cap.
When it happens
Trigger: Loading a graph.json larger than the default cap via _load_graph (graphify/serve.py) or any path that calls check_graph_file_size_cap; a huge repo producing a multi-GiB graph.json; cap lowered via env var while an old large graph remains on disk.
Common situations: Monorepos with enormous graphs; CI machines where GRAPHIFY_MAX_GRAPH_BYTES was set aggressively low; mixing graphs produced by different graphify versions with different serialization sizes.
Related errors
- Graph has {G.number_of_nodes()} nodes - too large for HTML v
- Response from {url!r} exceeds size limit ({max_bytes // 1_04
- git hooks path from {source} looks like a Windows path: {val
- outcome must be one of {OUTCOMES}, got {outcome!r}
- No LLM backend configured. Set one of: GEMINI_API_KEY, ANTHR
AI-assisted analysis of Graphify-Labs/graphify@7fe58b0b0f (2026-08-14).
Data as JSON: /api/errors/d525da81b1a94657.
Report an issue: GitHub.