Structured output for your memos
Project description
Basic Memory Hooks
Structured output for your memos.
Validates and formats memos before they're saved—catching LLM inconsistencies and fixing them automatically. No more hoping the model remembers your format. No more manual cleanup. Just consistent, machine-readable memos, every time.
The Problem
You ask an LLM to write a memo and get back something that almost follows your format:
## Observations
- fact: The API uses REST ← Wrong format
- [decision] Use Python ← Correct format
- This is important ← Missing category entirely
## Observations ← Duplicate section
- [fact] Another observation
Each inconsistency breaks your knowledge graph. Queries return garbage. Links fail.
The Solution
Basic Memory Hooks fixes these automatically:
## Observations
- [fact] The API uses REST
- [decision] Use Python
- [fact] This is important
- [fact] Another observation
Duplicate sections merged. Formats corrected. Content preserved.
Installation
pip install basic-memory-hooks
Quick Start
With Basic Memory Plugins
If you're using basic-memory-plugins, hooks integrate automatically:
You: /remember API design decision
↓
basic-memory-plugins prepares the memo
↓
basic-memory-hooks validates and fixes it
↓
Clean memo saved to your project
Install both, add a format.md config, and every /remember, /research, and /continue runs through validation.
Python Library
from basic_memory_hooks import HookEngine, HookStage
engine = HookEngine()
engine.load_config(".basic-memory/format.md")
result = engine.run(
stage=HookStage.PRE_WRITE,
content="# My Note...",
title="My Note",
)
if result.success:
print(result.content) # Cleaned content
else:
print("Errors:", result.errors)
Web API
python -m basic_memory_hooks # Starts FastAPI server
curl -X POST http://localhost:8000/validate \
-H "Content-Type: application/json" \
-d '{"content": "...", "title": "My Memo"}'
Why a Web API? Basic Memory Cloud uses it for server-side validation. Self-hosted setups can centralize validation across multiple agents. And API-only integrations—agents without a Python runtime—can call it over HTTP.
Configuration
Create .basic-memory/format.md in your project with YAML frontmatter:
---
version: "1.0"
strictness: balanced
note_types:
allowed: [memo, spec, decision, project]
quality:
minimum_observations: 1
require_tags: false
---
# Project Format Configuration
Your project-specific format rules.
Three strictness levels:
- strict: Errors fail validation. For production pipelines.
- balanced: Errors become warnings. Fixes what it can, accepts the rest.
- flexible: Only formatting hooks run. Maximum permissiveness.
Standard Hooks
| Hook | What it does |
|---|---|
| validate_frontmatter | Ensures title and type exist |
| validate_note_type | Type must be in allowed list |
| validate_minimum_observations | Minimum observation count |
| validate_observation_categories | Required categories must be used |
| format_observations | Fixes - category: to - [category] |
| remove_duplicate_headings | Merges duplicate sections |
| consolidate_observations | Combines multiple Observations sections |
| order_relations | Primary relations before secondary |
Custom Hooks
Add project-specific validation in .basic-memory/hooks/:
# .basic-memory/hooks/my_hook.py
from basic_memory_hooks import Hook, HookContext, HookResult, HookStage, HookPriority
class MyCustomHook(Hook):
@property
def name(self) -> str:
return "my_custom_hook"
@property
def stage(self) -> HookStage:
return HookStage.PRE_WRITE
@property
def priority(self) -> HookPriority:
return HookPriority.NORMAL
def execute(self, context: HookContext) -> HookResult:
# Your validation logic here
return HookResult(success=True)
Reference it in your format.md:
custom_hooks:
- path: hooks/my_hook.py
enabled: true
License
MIT
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 basic_memory_hooks-0.0.1.tar.gz.
File metadata
- Download URL: basic_memory_hooks-0.0.1.tar.gz
- Upload date:
- Size: 48.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
577d62c137b039531caf64561506c743ca1d13e996b68c0072eefb1b10270e8d
|
|
| MD5 |
95d7ca05bd43032d3a04338ed2b8b4e4
|
|
| BLAKE2b-256 |
6f73898b9e04c7db3648958c6b353f66a86647737983e90b0cc305a6cc1cb393
|
File details
Details for the file basic_memory_hooks-0.0.1-py3-none-any.whl.
File metadata
- Download URL: basic_memory_hooks-0.0.1-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73ac5bbedc0a36d0d9f18b15832ad006d776cde00079db85d393698786c23729
|
|
| MD5 |
cf3017d755df95d676bd99eff60d2107
|
|
| BLAKE2b-256 |
60aa2fdbc73d38de0bcce1361397a41e7f036c177138d255000dd40d877bc8a5
|