rules

package
v0.0.35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: Apache-2.0, MIT Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

draft/rules

The shared editorial constants the prompt builder and the validator both depend on.

Go reference Website

Word limits, banned vocabulary, metric vocabulary and the accepted claim taxonomy live here and nowhere else. Keeping them in one place guarantees the writer is told exactly what the validator enforces, and that the two cannot silently drift apart.

Contents

Install

go get github.com/sebastienrousseau/draft@latest
import "github.com/sebastienrousseau/draft/rules"

Quick start

package main

import (
	"fmt"

	"github.com/sebastienrousseau/draft/rules"
)

func main() {
	fmt.Printf("a draft must be %d-%d words\n", rules.MinWords, rules.MaxWords)

	// Banned words are matched on every inflection, not just the base form.
	// WordForm pairs the surface form with the inflection kind that produced
	// it ("base", "s", "ed" or "ing"), so a replacement can be inflected to match.
	for _, f := range rules.WordForms("leverage") {
		fmt.Printf("  %s (%s)\n", f.Form, f.Kind)
	}

	// Each banned term maps to a neutral replacement, so one stray cliché is
	// repaired in place instead of costing a full regeneration.
	fmt.Println("leverage →", rules.StyleReplacements["leverage"])

	// The claim taxonomy the verifier accepts.
	fmt.Println("valid TYPE 'result'?    ", rules.ClaimTypes["result"])
	fmt.Println("valid STRENGTH 'hedged'?", rules.ClaimStrengths["hedged"])

	// Structural markers the writer must emit and the validator checks for.
	fmt.Println(rules.H1Prefix, rules.H2Prefix, rules.ExecSummaryMarker)
}

API

Symbol Kind Purpose
MinWords, MaxWords const Word-count bounds for a finished body-only draft (500–3000). Both are enforced by validate.Errors, and the pipeline sizes generation against MaxWords
MinQuoteChars const Shortest verbatim source span a claim may cite (12)
PostLeadAsideMarker, ExecSummaryMarker, H1Prefix, H2Prefix const Structural markers the writer emits and the validator checks
BannedWords, BannedPhrases var []string Single tokens and multi-word clichés the house style forbids
StyleReplacements var map[string]string Every banned term → a neutral equivalent
AssertiveVerbs var []string Verbs that state a result as settled fact
MetricTerms var []string Evaluation metrics that must not appear ungrounded
WriterStopwords var map[string]bool Common words ignored when measuring token overlap
ClaimTypes, ClaimStrengths, HedgeStrengths var map[string]bool The accepted claim taxonomy
WordForms func(w string) []WordForm A banned word plus its common inflections, as {Form, Kind} pairs
InflectLike func(word, kind string) string Inflect a word using regular English spelling rules
MetricForms func(term string) []string Every surface form equivalent to a metric term

ClaimTypes accepts metric, mechanism, definition, method, result and limitation. ClaimStrengths accepts demonstrated, hedged and speculation-or-future-work; the latter two are also in HedgeStrengths.

Why one package

prompt reads these constants to tell the model what is expected; validate reads the same constants to enforce it; claims reads MinQuoteChars, ClaimTypes and ClaimStrengths to gate a record. Three consumers, one definition.

TestSkeletonMatchesStructureMarkers asserts that the writing prompt's output skeleton embeds each structural marker, so a change here that the prompt does not follow fails the build rather than the draft.

This package holds constants only. It imports nothing from the rest of the module, which is what lets everything else import it.

License

Licensed under either of Apache License 2.0 or MIT License, at your option. © Sebastien Rousseau.

Back to top ↑

Documentation

Overview

Package rules holds the shared editorial constants that both the prompt builder and the validator depend on: word limits, the banned vocabulary, metric vocabulary, and the accepted claim taxonomy. Keeping them in one place guarantees the writer is told exactly what the validator enforces.

Index

Examples

Constants

View Source
const (
	MinWords = 500
	MaxWords = 3000
)

Word-count bounds for a finished body-only draft.

View Source
const (
	// PostLeadAsideMarker opens the summary aside that carries the TL;DR and key
	// takeaways.
	PostLeadAsideMarker = `<aside class="post-lead"`
	// ExecSummaryMarker labels the executive-summary blockquote.
	ExecSummaryMarker = "Executive Summary"
	// H1Prefix begins the single title line; H2Prefix begins each section heading.
	H1Prefix = "# "
	H2Prefix = "## "
)

Structural markers the writer must emit and the validator checks for. They live here so the output template (the prompt package) and the validator share a single definition and cannot silently drift apart; TestSkeletonMatchesStructureMarkers enforces that the skeleton embeds each one.

View Source
const MinQuoteChars = 12

MinQuoteChars is the shortest verbatim source span a claim may cite.

Variables

View Source
var (
	ClaimTypes = map[string]bool{
		"metric": true, "mechanism": true, "definition": true,
		"method": true, "result": true, "limitation": true,
	}
	ClaimStrengths = map[string]bool{
		"demonstrated": true, "hedged": true, "speculation-or-future-work": true,
	}
	HedgeStrengths = map[string]bool{
		"hedged": true, "speculation-or-future-work": true,
	}
)

ClaimTypes and ClaimStrengths are the accepted enumerations for a claim record. Anything outside them is dropped during verification.

View Source
var AssertiveVerbs = []string{
	"demonstrates", "demonstrated", "proves", "proven", "proved",
	"establishes", "established", "confirms", "confirmed", "guarantees",
	"guaranteed", "ensures", "ensured", "shows that", "showed that",
}

AssertiveVerbs flag sentences that state a result as settled fact; combined with a hedged claim they signal a possible hedge upgrade.

View Source
var BannedPhrases = []string{
	"in today's fast-paced world", "at its core", "it's important to note",
	"furthermore", "moreover", "in conclusion", "in summary", "let's face it",
	"but here's the kicker", "when it comes to", "in the realm of",
	"look no further", "rest assured", "needless to say", "not only",
	"but also", "whether you're", "that said", "in essence", "ultimately",
	"paradigm shift", "the dawn of", "in today's world",
}

BannedPhrases are multi-word clichés the house style forbids.

View Source
var BannedWords = []string{
	"delve", "underscore", "testament", "foster", "maximize", "navigate",
	"tapestry", "catalyst", "elevate", "paradigm", "revolutionize",
	"paramount", "leverage", "harness", "unlock", "seamless", "robust",
	"realm", "landscape", "beacon", "game-changer", "cutting-edge",
	"utilize", "myriad", "vibrant", "bustling", "whimsical", "profound",
}

BannedWords are single tokens the house style forbids. They are matched on word boundaries, case-insensitively.

View Source
var MetricTerms = []string{
	"perplexity", "ppl", "cross-entropy", "cross entropy", "log-likelihood",
	"log likelihood", "bleu", "rouge", "f1", "wer", "cer",
	"bits per byte", "bits-per-byte",
}

MetricTerms are evaluation metrics that must never appear in a draft unless a verified claim also uses them, guarding against silent metric conversion.

View Source
var StyleReplacements = map[string]string{

	"delve": "examine", "underscore": "highlight", "testament": "sign",
	"foster": "encourage", "maximize": "increase", "navigate": "handle",
	"tapestry": "mix", "catalyst": "trigger", "elevate": "raise",
	"paradigm": "model", "revolutionize": "transform", "paramount": "essential",
	"leverage": "use", "harness": "use", "unlock": "enable", "seamless": "smooth",
	"robust": "strong", "realm": "area", "landscape": "field", "beacon": "example",
	"game-changer": "breakthrough", "cutting-edge": "advanced", "utilize": "use",
	"myriad": "many", "vibrant": "vivid", "bustling": "busy",
	"whimsical": "playful", "profound": "deep",

	"in today's fast-paced world": "today", "at its core": "essentially",
	"it's important to note": "note", "furthermore": "also", "moreover": "also",
	"in conclusion": "finally", "in summary": "overall", "let's face it": "admittedly",
	"but here's the kicker": "but", "when it comes to": "for", "in the realm of": "in",
	"look no further": "stop", "rest assured": "certainly", "needless to say": "clearly",
	"not only": "not just", "but also": "but", "whether you're": "whether you are",
	"that said": "still", "in essence": "essentially", "ultimately": "finally",
	"paradigm shift": "shift", "the dawn of": "the start of", "in today's world": "today",
}

StyleReplacements maps every banned word and phrase to a neutral, in-style equivalent, so a draft that trips the banned-vocabulary check can be repaired in place rather than regenerated — regeneration is slow and, on a small local model, simply produces fresh clichés. Every replacement is itself outside the banned lists; matching is case-insensitive and the replacement takes the case of the first matched character. Phrases are applied before single words, so a phrase that contains a banned word (for example "in the realm of") is rewritten whole. Keys must stay in sync with BannedWords and BannedPhrases.

View Source
var WriterStopwords = map[string]bool{
	"about": true, "above": true, "after": true, "again": true, "against": true,
	"along": true, "among": true, "around": true, "because": true, "before": true,
	"being": true, "below": true, "between": true, "beyond": true, "could": true,
	"does": true, "doing": true, "during": true, "either": true, "every": true,
	"framework": true, "further": true, "hence": true, "however": true, "into": true,
	"itself": true, "loops": true, "might": true, "other": true, "process": true,
	"rather": true, "result": true, "results": true, "since": true, "some": true,
	"such": true, "system": true, "than": true, "that": true, "their": true,
	"them": true, "then": true, "there": true, "these": true, "they": true,
	"those": true, "through": true, "under": true, "until": true, "using": true,
	"value": true, "when": true, "where": true, "which": true, "while": true,
	"with": true, "within": true, "would": true,
}

WriterStopwords are common words ignored when measuring token overlap between a draft sentence and a claim, so overlap reflects meaningful shared terms.

Functions

func InflectLike

func InflectLike(word, kind string) string

InflectLike inflects word to the given kind using regular English spelling rules (silent-e drop before "-ing", "-es" after a sibilant). An unknown kind — including "base" — returns word unchanged, so a banned form and its replacement stay aligned: "leverages" (kind "s") maps to InflectLike("use", "s") = "uses".

func MetricForms

func MetricForms(term string) []string

MetricForms returns every surface form equivalent to term (including term itself), so a grounding check accepts an abbreviation or expansion of the same metric rather than only a byte-for-byte match.

Types

type Style

type Style struct {
	MinWords      int      `json:"min_words"`
	MaxWords      int      `json:"max_words"`
	BannedWords   []string `json:"banned_words"`
	BannedPhrases []string `json:"banned_phrases"`
	// English is the language-variant instruction handed to the writer, e.g.
	// "British English" or "American English". Empty means no instruction.
	English string `json:"english"`
}

Style is the editorial policy a run enforces: the word band, the banned vocabulary, and the language variant. The defaults are this project's house style; a Style loaded from a file replaces or extends them, so a different publication can use draft's grounding without adopting its voice.

Only what a publication actually changes lives here. The structural rules — an H1, a lead aside, an executive summary, section headings — are the shape of a grounded article rather than a matter of taste, and stay fixed.

func DefaultStyle

func DefaultStyle() Style

DefaultStyle is draft's own house style: the values the prompt and validator used before the style file existed. A loaded style starts from this.

func LoadStyle

func LoadStyle(path string) (Style, error)

LoadStyle reads a JSON style file and returns it merged onto DefaultStyle, so a file that sets only one field keeps the defaults for the rest. An unknown field is an error, because a misspelled key that was silently ignored would leave the writer held to a rule the author thought they had changed.

func (Style) BannedWordForms

func (s Style) BannedWordForms() []string

BannedWordForms expands the style's banned words to their inflections, the set the validator matches on.

func (Style) OrDefault

func (s Style) OrDefault() Style

OrDefault returns DefaultStyle when the receiver is a zero value, so a Config built as a literal (in a test, or by an embedding caller) still has a usable style without every such caller remembering to set one.

type WordForm

type WordForm struct {
	Form string
	Kind string // "base", "s", "ed", or "ing"
}

WordForm is a surface form of a banned word paired with the inflection kind that produced it, so a replacement can be inflected the same way.

func WordForms

func WordForms(w string) []WordForm

WordForms returns the base banned word and its common inflections — plural or third-person ("s"), past ("ed"), and gerund ("ing") — so the validator and the style repair catch "leverages" and "leveraging", not only "leverage". Duplicate forms are returned in a stable order. It intentionally omits adverbial "-ly": the replacements do not carry adverb forms, so those are handled separately.

Example

WordForms expands a banned word into the inflections the validator must also catch, so "leverage" covers "leverages", "leveraging", and the rest.

package main

import (
	"fmt"

	"github.com/sebastienrousseau/draft/rules"
)

func main() {
	for _, f := range rules.WordForms("leverage") {
		fmt.Printf("%s (%s)\n", f.Form, f.Kind)
	}
}
Output:
leverage (base)
leverages (s)
leveraged (ed)
leveraging (ing)
leveragely (ly)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL