A Python SDK for parsing and validating LOGIC.md specifications — declarative reasoning configurations for AI agents.
Status: Alpha — parser and validator only.
pip install logic-mdfrom logic_md import parse, validate
# Parse a LOGIC.md file
with open("my-agent.logic.md") as f:
content = f.read()
result = parse(content)
if result.ok:
print(f"Parsed spec: {result.data['name']}")
else:
print(f"Parse errors: {result.errors}")
# Validate the parsed spec
val_result = validate(result.data)
if val_result.ok:
print("Spec is valid!")
else:
for error in val_result.errors:
print(f"Validation error at {error['path']}: {error['message']}")Extracts YAML frontmatter from a LOGIC.md file and returns a ParseResult:
ok: bool— True if parsing succeededdata: dict— Parsed YAML frontmatter (if ok=True)content: str— Markdown body after frontmattererrors: list[str]— Error messages (if ok=False)
Example:
result = parse("---\nspec_version: '1.0'\nname: my-agent\n---\n# My Agent")
# result.ok = True
# result.data = {"spec_version": "1.0", "name": "my-agent"}
# result.content = "# My Agent"Validates a parsed spec against the LOGIC.md JSON Schema and returns a ValidationResult:
ok: bool— True if spec is validdata: dict— The validated spec (if ok=True)errors: list[dict]— Validation errors withpath,keyword,message(if ok=False)
Example:
result = validate({"spec_version": "1.0", "name": "my-agent"})
# result.ok = True
# result.data = {"spec_version": "1.0", "name": "my-agent"}A TypedDict type hint for the parsed/validated spec structure. Use for type hints:
from logic_md import LogicSpec
def process_spec(spec: LogicSpec) -> None:
print(spec["name"])The validator uses the canonical JSON Schema from the logic-md spec repository.