CLI tool and Python library for working with OKF (Open Knowledge Format) bundles
Project description
okf-schema
okf-schema is a CLI tool and Python library for working with OKF (Open Knowledge Format) bundles with JSONSchema validation of the frontmatter metadata, and formatting capabilities while preserving comments.
OKF is a markdown-based knowledge format where each concept is a markdown file with YAML frontmatter.
[!IMPORTANT] OKF-schema is opinionated. It delivers a valid OKF bundle but is adds a structure on the frontmatter that is not allowed in OKF specification:
Type values are **not** registered centrally. Producers SHOULD pick values that are descriptive and self-explanatory; consumers MUST tolerate unknown types gracefully (typically by treating them as generic concepts).In a strict OKF bundle, the
typefield is mandatory but can take any value and the validator needs to allow any field in the frontmatter.OKF-schema requires the type to be one of the registered types in the
_schema/directory and validates the frontmatter against the corresponding schema. Additional properties may or may not be allowed depending on the schema definition.
What okf-schema adds to OKF
Plain OKF only defines a folder of markdown files. okf-schema turns those files into a validated, queryable knowledge base by adding:
| Capability | What it does |
|---|---|
| Schema-driven frontmatter validation | Every concept's YAML frontmatter is checked against a JSONSchema. Invalid fields, missing required keys, or wrong types are reported as structured errors. |
| Auto-discovered schemas | Schemas live inside the bundle under _schema/ (e.g. _schema/concept.schema.yaml). The type field in a concept's frontmatter tells okf-schema which schema file to load. A concept with type: concept is validated against _schema/concept.schema.yaml. Schemas can be written in YAML, JSON, or JSON5 (JSON with comments and trailing commas). |
| Bundle integrity checks | Detects broken internal links, missing index.md files, malformed log.md entries, and reserved-file violations. |
| Safe linting | Normalizes YAML frontmatter by flattening nested lists and converting block-style to inline notation while preserving comments and custom quotes via ruamel.yaml. |
| Analytics | Bundle statistics. |
See a real schema definition in examples/ai-llm-knowledge-base/_schema/concept.schema.yaml.
Example of structure
my-bundle/
├── _schema/
│ ├── concept.schema.yaml
│ ├── tool.schema.json
│ └── paper.schema.json5
├── concepts/
│ ├── rag.md
│ └── chain-of-thought.md
├── tools/
│ ├── langchain.md
│ └── llamaindex.md
├── papers/
│ ├── rag-paper.md
│ └── chain-of-thought-paper.md
├── index.md
└── log.md
The type field in each entity frontmatter determines which schema is used for validation.
For example, type: concept uses _schema/concept.schema.yaml, while type: tool uses _schema/tool.schema.json.
Schema extensions supported:
.schema.yaml— YAML (human-friendly, supports comments and anchors).schema.json— JSON (strict syntax, widely supported by editors).schema.json5— JSON5 (JSON with comments, trailing commas, and unquoted keys)
Installation
uv tool install okf-schema
Quickstart
# Initialize a new OKF bundle
okf-schema init my-bundle
# Update index.md files for all directories
okf-schema index --path my-bundle/bundle
# Lint frontmatter (flatten nested lists and convert block-style to inline)
okf-schema lint --path my-bundle/bundle
# Validate a bundle
okf-schema validate --path my-bundle/bundle
# or enforce strict validation (fail on warnings)
okf-schema validate --path my-bundle/bundle --strict
# List all concepts
okf-schema list --path my-bundle/bundle
CLI Reference
| Subcommand | Description |
|---|---|
init <name> |
Create a new OKF bundle directory structure |
new --path <dir> --name <name> |
Create a new concept file with frontmatter template |
validate --path <bundle> |
Validate bundle structure and frontmatter |
validate --path <bundle> --strict |
Validate and fail on warnings |
lint --path <bundle> |
Lint frontmatter: flatten nested lists and convert block-style to inline |
list --path <bundle> |
List all concepts in a bundle |
show --path <bundle> <concept> |
Show a single concept's frontmatter and body |
index --path <bundle> |
Regenerate all index.md files |
stats --path <bundle> |
Show bundle statistics |
Recommended Workflow
Before packaging or distributing a bundle, run these three commands in order and fix all warnings:
okf-schema index --path my-bundle/bundle # regenerate index.md files
okf-schema lint --path my-bundle/bundle # flatten nested lists and convert block lists to inline
okf-schema validate --path my-bundle/bundle --strict # check structure, schema, and links; fail on warnings
Only zip or ship the bundle once validate --strict reports zero errors and zero warnings. Warnings such as missing index.md (W4), block-style lists (W7), or broken cross-links (W2) signal issues that will degrade the experience for downstream consumers.
Example: AI & LLM Knowledge Base
The examples/ai-llm-knowledge-base/ directory contains a realistic knowledge base with three concept types — concept, tool, and paper — each validated by its own schema in _schema/.
How type selects the schema
The type field in a concept's frontmatter determines which schema file is loaded. A file with type: concept is validated against _schema/concept.schema.yaml; type: tool against _schema/tool.schema.json; and type: paper against _schema/paper.schema.json5.
Schema format support
okf-schema accepts schemas in three formats:
| Extension | Format | Notes |
|---|---|---|
.schema.yaml |
YAML | Human-friendly, supports comments and anchors |
.schema.json |
JSON | Strict syntax, widely supported by editors |
.schema.json5 |
JSON5 | JSON with comments, trailing commas, and unquoted keys |
Schema highlights
concept.schema.yaml — AI concepts with enums, email validation, and kebab-case regex:
properties:
category:
enum: [LLM, AI Agent, Coding Agent, Prompt Engineering, Tooling, Evaluation]
maturity:
enum: [experimental, beta, production, deprecated]
author_email:
type: string
format: email
tags:
type: array
items:
pattern: "^[a-z0-9-]+$" # kebab-case only
tool.schema.json — Developer tools with URI validation and language enums:
{
"properties": {
"license": {
"enum": ["MIT", "Apache-2.0", "GPL-3.0", "Proprietary", "Other"]
},
"language": {
"enum": ["Python", "JavaScript", "TypeScript", "Rust", "Go", "Java", "Multi-language"]
},
"url": { "type": "string", "format": "uri" }
}
}
paper.schema.json5 — Research papers with year bounds and venue enums:
// JSON5 allows comments, trailing commas, and unquoted keys
{
properties: {
year: { type: "integer", minimum: 1950, maximum: 2030 },
venue: {
enum: ["NeurIPS", "ICML", "ICLR", "ACL", "EMNLP", "arXiv", "Other"]
},
bibtex_key: { pattern: "^[A-Za-z0-9_-]+$" },
},
}
Concept file example (concepts/rag.md)
---
type: concept
title: Retrieval-Augmented Generation
description: >
A technique that enhances LLM outputs by retrieving relevant documents
from an external knowledge store and injecting them into the prompt.
category: LLM
maturity: production
author_email: bob@example.com
complexity: intermediate
tags: [rag, retrieval, llm, knowledge-base]
related_tools: [LangChain, LlamaIndex, OpenAI-API]
---
# Retrieval-Augmented Generation
RAG combines parametric knowledge (the model's weights) with non-parametric
knowledge (external documents) to reduce hallucinations...
Validation in action
# Validates all concepts, tools, and papers against their respective schemas
okf-schema validate --path examples/ai-llm-knowledge-base
# Show bundle statistics
okf-schema stats --path examples/ai-llm-knowledge-base
Python API
from okf_schema.api import validate_bundle
report = validate_bundle("path/to/bundle")
for finding in report.findings:
print(finding.level, finding.message)
# The _schema/ directory inside the bundle is auto-discovered.
# You can also pass an explicit schema_db path:
# report = validate_bundle("path/to/bundle", schema_db="path/to/schemas")
Documentation
Full documentation is available at https://okf-schema.readthedocs.io.
Contributing
See CONTRIBUTING.md for development setup and guidelines.
License
MIT License — see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file okf_schema-0.2.0.tar.gz.
File metadata
- Download URL: okf_schema-0.2.0.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0625a947516b331a5f10a6dec9692a3d118c7651f5ad390dd4b69cd06e4a6f82
|
|
| MD5 |
70f5542db02a3d5c94b9693fda9e6a83
|
|
| BLAKE2b-256 |
48775bd32415f20f0a812c8bd745c0708a98e353731a4f0f746542706b78a426
|
Provenance
The following attestation bundles were made for okf_schema-0.2.0.tar.gz:
Publisher:
publish.yml on gsemet/okf-schema
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
okf_schema-0.2.0.tar.gz -
Subject digest:
0625a947516b331a5f10a6dec9692a3d118c7651f5ad390dd4b69cd06e4a6f82 - Sigstore transparency entry: 2010411600
- Sigstore integration time:
-
Permalink:
gsemet/okf-schema@df346106c79f3c4aeb85fd391c491edf0e78a47c -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/gsemet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@df346106c79f3c4aeb85fd391c491edf0e78a47c -
Trigger Event:
release
-
Statement type:
File details
Details for the file okf_schema-0.2.0-py3-none-any.whl.
File metadata
- Download URL: okf_schema-0.2.0-py3-none-any.whl
- Upload date:
- Size: 24.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6f1341fd725a8d4162be9dd5916f547231ea5f40b872633632f75390275309c
|
|
| MD5 |
be8e14b23c98b641c00336207d43d854
|
|
| BLAKE2b-256 |
77c2bad39f96c5abb29e6811328134b2c2af8567798cf0b1b4c0b65dddba5dcf
|
Provenance
The following attestation bundles were made for okf_schema-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on gsemet/okf-schema
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
okf_schema-0.2.0-py3-none-any.whl -
Subject digest:
f6f1341fd725a8d4162be9dd5916f547231ea5f40b872633632f75390275309c - Sigstore transparency entry: 2010411666
- Sigstore integration time:
-
Permalink:
gsemet/okf-schema@df346106c79f3c4aeb85fd391c491edf0e78a47c -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/gsemet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@df346106c79f3c4aeb85fd391c491edf0e78a47c -
Trigger Event:
release
-
Statement type: