Skip to content

Commit c8f96eb

Browse files
committed
fix: prevent duplicate frontmatter in LLM-generated content
Remove frontmatter format from schema to avoid LLM copying it. Add strip as fallback in _write_summary and _write_concept create path.
1 parent 15f970d commit c8f96eb

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

openkb/agent/compiler.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ def _read_concept_briefs(wiki_dir: Path) -> str:
283283
def _write_summary(wiki_dir: Path, doc_name: str, summary: str,
284284
doc_type: str = "short") -> None:
285285
"""Write summary page with frontmatter."""
286+
if summary.startswith("---"):
287+
end = summary.find("---", 3)
288+
if end != -1:
289+
summary = summary[end + 3:].lstrip("\n")
286290
summaries_dir = wiki_dir / "summaries"
287291
summaries_dir.mkdir(parents=True, exist_ok=True)
288292
ext = "md" if doc_type == "short" else "json"
@@ -347,6 +351,10 @@ def _write_concept(wiki_dir: Path, name: str, content: str, source_file: str, is
347351
existing = fm + body
348352
path.write_text(existing, encoding="utf-8")
349353
else:
354+
if content.startswith("---"):
355+
end = content.find("---", 3)
356+
if end != -1:
357+
content = content[end + 3:].lstrip("\n")
350358
fm_lines = [f"sources: [{source_file}]"]
351359
if brief:
352360
fm_lines.append(f"brief: {brief}")

openkb/schema.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@
3535
3636
## Format
3737
- Use [[wikilink]] to link other wiki pages (e.g., [[concepts/attention]])
38-
- Summary pages header: `doc_type: short|pageindex` and `full_text: sources/{name}.md|.json`
39-
- Concept pages header: `sources: [summaries/doc1.md, summaries/doc2.md, ...]`
4038
- Standard Markdown heading hierarchy
4139
- Keep each page focused on a single topic
40+
- Do not include YAML frontmatter (---) in generated content; it is managed by code
4241
"""
4342

4443
# Backward compat alias

0 commit comments

Comments
 (0)