Skip to main content

scripts-frontmatter-judge

#!/usr/bin/env python3 """

title: Frontmatter Judge component_type: script version: 1.0.0 status: active summary: Validates MoE classification against frontmatter declarations with veto authority keywords:

  • judge
  • frontmatter
  • validation
  • moe
  • veto tags:
  • script
  • moe-classifier
  • judge created: '2025-12-15' updated: '2026-01-16' script_name: frontmatter_judge.py language: python python_version: '3.10+'

Frontmatter Judge - Validates classification against frontmatter declarations. """

from typing import List, Optional from .base import BaseJudge, JudgeDecision

class FrontmatterJudge(BaseJudge): """Validates classification against frontmatter metadata. Has veto authority."""

name = "frontmatter"
has_veto_authority = True
weight = 1.5 # Higher weight - frontmatter is authoritative

def evaluate(self, document, votes, consensus) -> JudgeDecision:
frontmatter = getattr(document, 'frontmatter', {}) or {}

declared_type = (
frontmatter.get('component_type') or
frontmatter.get('type') or
frontmatter.get('doc_type')
)

if declared_type:
declared_type = declared_type.lower().strip()
classification = consensus.classification.lower() if consensus.classification else ""

if declared_type != classification:
return JudgeDecision(
judge=self.name,
approved=False,
reason=f"Frontmatter declares '{declared_type}' but classified as '{classification}'",
confidence=0.95,
metadata={'declared': declared_type, 'classified': classification, 'veto': True}
)

return JudgeDecision(
judge=self.name,
approved=True,
reason=f"Frontmatter confirms type: {declared_type}",
confidence=0.95,
metadata={'declared': declared_type}
)

return JudgeDecision(
judge=self.name,
approved=True,
reason="No frontmatter type declaration to validate",
confidence=0.5,
metadata={'no_declaration': True}
)