Skip to content
This repository was archived by the owner on Nov 15, 2025. It is now read-only.
This repository was archived by the owner on Nov 15, 2025. It is now read-only.

[Feature] Guideline Reinforcement Engine – Enforce Prompt Rules in Markdown, YAML, SudoLang #19

@christso

Description

@christso

Problem

bbeval opt must generate structured, compliant prompts in Markdown, YAML, or SudoLang, while enforcing company guidelines (attached via --guidelines) Invalid prompts (missing {{examples}}, banned phrases, wrong format) must be rejected during optimization.

Proposed Solution

Add a multi-format Guideline Reinforcement Engine to bbeval opt that:

  • Validates every candidate before scoring
  • Supports Markdown, YAML, and SudoLang output
  • Enforces format-specific rules via --guidelines (YAML)

CLI Usage

bbeval opt tests.yaml base.prompt.md \
  --mode direct-llm \
  --guidelines constraints.yaml \
  --format markdown \
  --output optimized.prompt.md

constraints.yaml (Format-Agnostic + Format-Specific)

# Global
required_placeholders:
  - "{{task}}"
  - "{{guidelines}}"
banned_phrases:
  - "never"
  - "always avoid"
max_tokens: 500

# Format: Markdown
markdown:
  required_headers:
    - "# Task"
    - "## Output"
  required_tools_in_frontmatter: true
  no_universal_concepts: true  # Ban SOLID, PascalCase, etc.

# Format: YAML
yaml:
  required_keys:
    - persona
    - workflow
    - output
  no_inheritance: true  # Ban `extends`, `class`

# Format: SudoLang
sudolang:
  no_class_keywords: true
  prefer_natural_language: true
  required_constraints_block: true
  lint_rules: true  # Auto-run SudoLang linter

Supported Output Formats

Format When to Use Validation
Markdown (default) Single workflow, clear steps Headers, frontmatter, placeholders
YAML Multi-workflow, context-aware Keys, no class, composition
SudoLang Loops, branching, state No new, constraints, lint

Auto-selection: bbeval opt picks simplest format that fits logic (Markdown > YAML > SudoLang).


Enforcement Flow

def validate_candidate(prompt_str: str, format: str) -> (bool, str):
    # 1. Parse (Markdown → AST, YAML → dict, SudoLang → lint)
    # 2. Check global rules (tokens, phrases)
    # 3. Check format-specific rules

# In optimizer:
if not validate_candidate(candidate, format):
    score = 0.0  # Reject early

Example: Optimized Markdown Output

---
description: 'SQL schema review'
mode: 'ask'
tools: ['runInTerminal', 'getTerminalOutput']
---

# SQL Schema Reviewer

You are a senior DBA with 15 years in fintech.

## Task
Review `${selection}` for compliance with internal SQL standards.

{{guidelines}}

## Instructions
1. Run `EXPLAIN` via terminal
2. Check for missing indexes
3. Suggest fixes only if critical

## Output
```diff
- Old
+ New

SudoLang Linter Integration

# constraints.yaml
sudolang:
  lint: true

→ Auto-runs:

Lint { style constraints { * obey style guide; prohibit (class) } }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions