pydantic-handlebars
CLAUDE.md24 starsChanged 9 months agoMITView on GitHub
Handlebars template engine for composing LLM prompts, built on Pydantic. Templates may be untrusted. All context data is serialized to JSON-safe types via pydantic_core.to_jsonable_python before rendering — the template engine only sees dicts, lists, strings, numbers, bools, and None. Enforce depth limits for nesting. Tests are ported from https://github.com/handlebars-lang/handlebars.js/tree/master/spec. When adding new features, find the corresponding JS spec tests and port them. Use assert render(template, context) == expected pattern. No test classes — standalone functions only.
The file
We split this CLAUDE.md into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Only runtime dependency is pydantic (2.0+)
- Very specific: line 16
All implementation modules are private (_tokenizer.py, etc.)
- Distinctive: line 23
No imports inside functions
≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
pydantic-handlebars
Handlebars template engine for composing LLM prompts, built on Pydantic.
Quick Reference
make all— format, lint, typecheck, test with coveragemake test— run tests (parallel with pytest-xdist)make lint— ruff format check + ruff checkmake typecheck— pyright strict mode
Code Rules
- Only runtime dependency is pydantic (2.0+)
- 100% test coverage required
- All implementation modules are private (
_tokenizer.py, etc.) - Public API is exported from
__init__.py - Tests are ported from the Handlebars.js spec suite — maintain 1:1 correspondence
- Single quotes for code, double quotes for docstrings
- Google-style docstrings
- Python 3.10+ (use
X | Yunion syntax in annotations, butisinstance(x, (X, Y))in runtime checks) - No
except Exception— catch specific types - No imports inside functions
Architecture
- Tokenizer (
_tokenizer.py) → Token stream - Parser (
_parser.py) → AST (_ast_nodes.py) - Compiler (
_compiler.py) → Output string
Security
Templates may be untrusted. All context data is serialized to JSON-safe types via pydantic_core.to_jsonable_python before rendering — the template engine only sees dicts, lists, strings, numbers, bools, and None. Enforce depth limits for nesting.
Testing
Tests are ported from https://github.com/handlebars-lang/handlebars.js/tree/master/spec. When adding new features, find the corresponding JS spec tests and port them. Use assert render(template, context) == expected pattern. No test classes — standalone functions only.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

