Repository navigation
Description
graphify extract --backend claude crashes on 'ThinkingBlock' object has no attribute 'text'
Summary
graphify/llm.py reads the Anthropic response as resp.content[0].text. On every current
Claude model, content[0] is a ThinkingBlock, not a TextBlock — so semantic
extraction fails with:
AttributeError: 'ThinkingBlock' object has no attribute 'text'
--code-only is unaffected (it never calls the LLM).
This is not limited to unusual setups. Extended thinking is on by default on current
models, and thinking blocks are present in content even when the thinking text is
suppressed: with thinking.display: "omitted" — the default — responses still include a
thinking block whose thinking field is an empty string. So the first block is a
ThinkingBlock on the ordinary default path, with no special configuration.
Root cause
Two sites, both assuming content[0] is the text block:
graphify/llm.py:1326 — semantic extraction:
raw_content = resp.content[0].text if resp.content else Nonegraphify/llm.py:2597 — community labelling (label / cluster-only):
return resp.content[0].text if resp.content else ""With thinking enabled, the SDK returns:
[ThinkingBlock(type='thinking', thinking='...'), TextBlock(type='text', text='...')]The Anthropic SDK documents that content may contain ThinkingBlock objects; indexing
position 0 for the text is not safe.
Steps to reproduce
import anthropic
client = anthropic.Anthropic(api_key="YOUR_API_KEY")
resp = client.messages.create(
model="claude-opus-5", # thinking is on by default on current models
max_tokens=1024,
messages=[{"role": "user", "content": 'Return valid JSON: {"nodes":[]}'}],
)
print([b.type for b in resp.content]) # -> ['thinking', 'text']
print(resp.content[0].text) # -> AttributeError: 'ThinkingBlock' ...
# What the code should do instead: take the first block of type "text"
text = next((b.text for b in resp.content if getattr(b, "type", None) == "text"), None)
print(text) # -> '{"nodes":[]}'The same happens through any Anthropic-compatible gateway with reasoning enabled
(LiteLLM, claude-code-router, corporate proxies), which is how we hit it.
Actual behavior
Real run, 26 markdown files, 15 semantic chunks:
[graphify] chunk 1/15 failed: 'ThinkingBlock' object has no attribute 'text'
[graphify] chunk 3/15 failed: 'ThinkingBlock' object has no attribute 'text'
...
[graphify] WARNING: 13/15 semantic chunk(s) failed — see errors above. Partial results returned.
13 of 15 chunks failed; 2 succeeded. The survivors are the responses that happened to
come back with no thinking block, which is what makes the failure look intermittent rather
than systematic.
Expected behavior
graphify extract --backend claude completes regardless of whether the model or gateway
returns thinking blocks.
Suggested fix
Take the first text block instead of the first block:
--- a/graphify/llm.py
+++ b/graphify/llm.py
@@ -1323,7 +1323,9 @@ def _anthropic_extract_chunk(...):
messages=[{"role": "user", "content": _anthropic_content(user_message, images or [])}],
)
- raw_content = resp.content[0].text if resp.content else None
+ raw_content = next(
+ (b.text for b in (resp.content or []) if getattr(b, "type", None) == "text"), None
+ )
result = _parse_llm_json(raw_content or "{}")
@@ -2594,7 +2596,9 @@ def _anthropic_label_chunk(...):
u = getattr(resp, "usage", None)
if u is not None:
_rec(getattr(u, "input_tokens", 0), getattr(u, "output_tokens", 0))
- return resp.content[0].text if resp.content else ""
+ return next(
+ (b.text for b in (resp.content or []) if getattr(b, "type", None) == "text"), ""
+ )Backward compatible: with no thinking block, next(...) finds the only TextBlock and
returns exactly what the original code returned.
We applied this patch locally and the same corpus that produced 13/15 failures completed
12/12 chunks on the next run.
Environment
| Field | Value |
|---|---|
graphify (PyPI graphifyy) |
0.9.41 |
anthropic SDK |
0.121.0 |
| Python | 3.13.12 |
| OS | Windows 11 |
| Endpoint | Anthropic-compatible gateway with reasoning enabled |
Note on the second site
llm.py:2597 (community labelling) has the identical pattern. It surfaces only when
graphify label / cluster-only invokes LLM naming, so it fails less visibly — but it is
the same bug and needs the same fix.
Activity
kam1-ui commentedon Aug 14, 2026
Confirming this, with three additions.
1. It goes back much further than 0.9.41. Same two sites on 0.9.13, at
llm.py:1126(extraction) andllm.py:2048(community labelling). And it is still present on upstreamv8today, at lines 1334 and 2605 — so upgrading does not currently escape it.2. It reproduces without an API key, which makes it cheap to add as a regression test:
Backward compatibility holds: with a single
TextBlockand no thinking block,next(...)returns exactly whatcontent[0].textreturned.3. The cost impact is larger than it looks, because this compounds with #2692.
Taken alone, this bug fails chunks. Combined with #2692 — where the real failure cause is masked by hook teardown noise on stderr — the operator cannot see why chunks failed. Failed files stay cache-misses, get re-extracted on the next run, and are re-billed. The loop is: fail here → cannot diagnose there → retry → re-bill → repeat.
That is not a hypothetical. It is how a semantic-extraction run on a text corpus turned into runaway cost on our side, months ago, on a VPS that eventually hit an automatic stop. We concluded at the time that "Claude is expensive for text extraction" and wrote a standing rule against using the Claude backend at all — while keeping it for code, since
--code-onlynever calls the LLM and was always fine.That conclusion was wrong. It was not a cost characteristic, it was these two bugs. Worth noting because other users likely drew the same inference and quietly switched backends rather than filing anything.
Suggested fix is the one already proposed in this issue. Applied locally to both sites on 0.9.13; extraction and labelling behave correctly, and the no-thinking-block path is unchanged.
Environment: graphify (PyPI
graphifyy) 0.9.13, Python 3.12, Debian 12.fix(claude): read text blocks after a leading ThinkingBlock (#2697)
test(claude): lock first-text-block (not concatenation) for the Think…
chore: bump to 0.9.47
safishamsi commentedon Aug 19, 2026
Fixed in v0.9.47: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.47 (the claude backend now reads the first text block past a leading ThinkingBlock). Closing as resolved.