Commit 3fb9428
fix(kg): kg_llm_extractor rewrites AGE dollar-quote tag in triples (#320)
Closes #313.
Drawers indexing palace-daemon / mempalace source code contain
mp_age_q verbatim (the AGE dollar-quote tag the cypher wrapper uses
to delimit its outer SQL literal). The LLM extractor was passing
those tag substrings straight through to add_triple, where
_cypher_literal's defensive check correctly rejected them — but
the rejection meant the drawer's KG presence was incomplete and
the worker logged a warning per failed write.
The error message itself says where the fix belongs: "reject
upstream in the sanitizer". This change adds the rewrite at
_validate — the boundary where the LLM hands triples back —
replacing 'mp_age_q' with 'MP_AGE_Q_LIT'. The case-sensitive
substring check in _cypher_literal no longer fires on the
rewritten value (Python's `in` operator is case-sensitive).
Predicate normalization happens before the rewrite, so the
lowercased predicate's tag substring gets caught and the final
predicate ends up with the upper-case placeholder — readable,
KG-queryable, safe.
Six new tests in tests/test_kg_extractor.py cover the rewrite
on each field, leave-clean-triples-unchanged, multiple-occurrence,
and an end-to-end roundtrip that proves the rewritten triple
survives _cypher_literal without raising.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 16c1edc commit 3fb9428
6 files changed
Lines changed: 360 additions & 166 deletions
File tree
- docs
- mempalace
- tests
- website/public
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
257 | 289 | | |
258 | 290 | | |
259 | 291 | | |
| |||
0 commit comments