Skip to main content

A linter for your LLM-compiled knowledge base

Project description

kb-lint

PyPI Python License Tests

A linter for your LLM-compiled knowledge base.

Run health checks over markdown wikis to catch broken links, missing metadata, orphan pages, thin articles, and structural inconsistencies - all without requiring an LLM.

Inspired by Andrej Karpathy's LLM Knowledge Bases workflow - he runs "health checks" over his wiki to "find inconsistent data, impute missing data, find interesting connections for new article candidates."

Installation

pip install kb-lint

Quick Start

# Lint the current directory
kb-lint .

# Generate a health report
kb-lint ./my-wiki --report

# Auto-fix simple issues
kb-lint ./my-wiki --fix

Example Output

 Knowledge Base Health Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  Path:     ./wiki
  Articles: 47
  Links:    203

  3 errors  7 warnings  2 info

┌─────┬──────────────────────┬───────┬──────────────┬─────────────────────────────────────┐
│ Sev │ File                 │  Line │ Check        │ Message                             │
├─────┼──────────────────────┼───────┼──────────────┼─────────────────────────────────────┤
│ E   │ concepts/rlhf.md     │    23 │ links        │ Broken wiki-link: [[ppo-training]]  │
│ E   │ concepts/scaling.md  │     1 │ frontmatter  │ Missing required field: title         │
│ W   │ concepts/new-idea.md │     - │ content      │ Thin article: only 42 words (min 100)│
│ W   │ sources/paper-x.md   │     - │ orphans      │ Orphan page: no incoming links        │
│ I   │ concepts/nlp.md      │     - │ consistency  │ Inconsistent tag casing for 'nlp'     │
└─────┴──────────────────────┴───────┴──────────────┴─────────────────────────────────────┘

  2 issues can be auto-fixed with --fix

Health Score: 82/100

Checks Reference

Check What it catches Default severity Auto-fixable?
links Broken [[wiki-links]] (wiki-links only, no external URLs) Error No
frontmatter Missing/invalid YAML frontmatter Error/Info Yes (add defaults)
orphans Articles with no incoming links Warning No
structure Non-kebab-case filenames, spaces Error/Warning Yes (rename)
content Thin articles, {{PLACEHOLDERS}}, duplicate titles, empty sections Error/Warning No
index Missing/extra entries in _index.md Warning/Error Yes (update index)
consistency Inconsistent tags, dates, confidence levels Warning No

CLI Reference

# Basic lint
kb-lint [path]

# Output formats
kb-lint [path] --format terminal    # Rich colored output (default)
kb-lint [path] --format markdown    # Markdown report
kb-lint [path] --format json        # Machine-readable JSON

# Filter by severity
kb-lint [path] --severity error     # Only show errors
kb-lint [path] --severity warning   # Warnings and errors

# Run specific checks
kb-lint [path] --check links,frontmatter

# List available checks
kb-lint --list-checks

# Health report with score
kb-lint [path] --report

# CI mode (exit 1 on errors)
kb-lint [path] --ci

# Auto-fix
kb-lint [path] --fix

# Preview fixes without applying them
kb-lint [path] --fix --dry-run

--ci Mode

In CI mode, kb-lint exits with code 1 if any errors are found:

kb-lint [path] --ci

--fix Behavior

--fix creates .bak backup files before modifying any file. Use --fix --dry-run to preview what would be changed without writing to disk.

Exit Codes

Code Meaning
0 Success - no errors found (warnings/info may still be present)
1 Errors found (only in --ci mode)

Configuration

Configure via .kblintrc.yml in your wiki directory:

required_frontmatter:
  - title
recommended_frontmatter:
  - tags
  - sources
  - created
  - confidence
min_article_words: 100
ignore_patterns:
  - _templates/**
  - drafts/**
recognized_directories:
  - concepts
  - sources
  - comparisons
allowed_confidence_levels:
  - high
  - medium
  - low
severity_threshold: info

Or in pyproject.toml:

[tool.kb-lint]
required_frontmatter = ["title"]
min_article_words = 100

CI Integration

GitHub Actions

- name: Lint knowledge base
  run: |
    pip install kb-lint
    kb-lint ./wiki --ci

Part of the LLM KB Ecosystem

FAQ

How do I lint a markdown knowledge base?

Install kb-lint with pip install kb-lint, then run kb-lint ./your-wiki to scan all markdown files. Use --report to get a health score, or --ci for CI pipelines that should fail on errors.

What does kb-lint check?

kb-lint checks for broken [[wiki-links]], missing YAML frontmatter, orphan pages with no incoming links, thin articles below a word count threshold, structural issues like non-kebab-case filenames, and inconsistencies in tags, dates, and confidence levels.

Can kb-lint auto-fix issues?

Yes. Run kb-lint ./your-wiki --fix to auto-fix supported issues like missing frontmatter defaults, non-kebab-case filenames, and out-of-date index files. Use --fix --dry-run to preview changes before applying them.

Does kb-lint work with Obsidian vaults?

kb-lint works with any folder of markdown files that uses [[wiki-links]]. Obsidian vaults fit this pattern well. Just point kb-lint at your vault directory and it will scan all .md files, including nested folders.

How is kb-lint different from markdownlint?

markdownlint checks markdown syntax and formatting (heading style, line length, etc.). kb-lint checks knowledge base structure - broken wiki-links, orphan pages, missing metadata, thin content, and cross-article consistency. They complement each other.

Development

git clone https://github.com/SingggggYee/kb-lint
cd kb-lint
pip install -e ".[dev]"
pytest -v
ruff check src/ tests/

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kb_lint-0.1.1.tar.gz (66.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kb_lint-0.1.1-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file kb_lint-0.1.1.tar.gz.

File metadata

  • Download URL: kb_lint-0.1.1.tar.gz
  • Upload date:
  • Size: 66.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.6

File hashes

Hashes for kb_lint-0.1.1.tar.gz
Algorithm Hash digest
SHA256 78d2aeb284bee383263c8579c02e5b12d8ef54a998e429b7feec28f240d66faf
MD5 855d32ec2b3b27fcf16dc05c652624ea
BLAKE2b-256 bac002276f7574c0da3fa264c59e5ec09469a67e1620593c219b17380eab8c9b

See more details on using hashes here.

File details

Details for the file kb_lint-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: kb_lint-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 27.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.6

File hashes

Hashes for kb_lint-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 54f2097f826c2b903a999611ac2d791ccf76e33230c9c949b8598865f31b330f
MD5 6b21ae2be508592971f47d96eca1032e
BLAKE2b-256 86c2b56ce5f0353c2022d54ee9aa960aee531cf2d36351000244209d612b9aa8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page