Documentation
¶
Overview ¶
Package validate enforces the house article rules before a draft is saved: required structure, length, banned vocabulary, emoji, truncation, and faithfulness to the verified claim ledger.
Index ¶
- func Baselines(article string, records []claims.Record) []string
- func ContainsEmoji(s string) bool
- func DuplicateParagraphIndexes(article string) []int
- func EndsSentence(tail string) bool
- func Errors(md string) []string
- func ErrorsWithSkeleton(md string, style rules.Style, sk skeleton.Skeleton) []string
- func ErrorsWithStyle(md string, style rules.Style) []string
- func Faithfulness(article string, records []claims.Record) (errs, warnings []string)
- func FaithfulnessWithOptions(article string, records []claims.Record, opts Options) (errs, warnings []string)
- func LimitationCounts(article string, given []claims.Record) (total, kept int)
- func LimitationRetention(article string, given []claims.Record) (errs, warnings []string)
- func LooksLikeArticle(s string) bool
- func Paragraphs(article string) []string
- func SeparatePopulations(article string, records []claims.Record) []string
- func UnsafeMarkup(md string) []string
- func WordCount(s string) int
- type Options
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Baselines ¶ added in v0.0.53
Baselines checks that a comparison in the article is stated against what the source compared it with, and in the source's units.
- A sentence that makes a comparison and states a number from a comparative claim must name that claim's baseline: the phrase after "than", "over", "versus", "relative to", "compared with" or "against" in the claim. One shared word is enough, so "the baseline" for "the dense baseline" passes; "GPT-4" for it does not.
- A difference of two percentages is in points. The article writing "3.7%" where the source has 45.2% against 41.5%, or says "3.7 points", turns an absolute gain into a relative one. A percentage any claim states as a percentage is left alone.
The 2026-12-07 article did both. Findings are warnings, and errors under Options.StrictNumbers, since both are a number stated wrongly.
func ContainsEmoji ¶
ContainsEmoji reports whether s contains a pictographic or symbol emoji.
func DuplicateParagraphIndexes ¶
DuplicateParagraphIndexes returns the indexes, within Paragraphs(article), of paragraphs that nearly duplicate an earlier one. Headings and short paragraphs are never reported: a repeated heading is structure, and short runs of shared words are not evidence of duplication.
func EndsSentence ¶
EndsSentence reports whether the trailing text closes on sentence-ending punctuation. It decodes the final rune (not the final byte) so multibyte closers — smart quotes, apostrophe, ellipsis — are recognised rather than mistaken for a truncated fragment.
func Errors ¶
Errors reports the house-rule violations in a finished body under the default house style. See ErrorsWithStyle for the per-style variant.
Example ¶
package main
import (
"fmt"
"github.com/sebastienrousseau/draft/validate"
)
func main() {
fmt.Println(validate.Errors("not a valid article")[0])
}
Output: body-only mode must start with a Markdown H1
func ErrorsWithSkeleton ¶ added in v0.0.57
ErrorsWithSkeleton is ErrorsWithStyle for an article shape: the structure a draft is held to comes from sk, the word band and vocabulary from the style. The "article" skeleton holds a draft to what ErrorsWithStyle always did.
func ErrorsWithStyle ¶
ErrorsWithStyle checks a body against a specific editorial style: the word band and banned vocabulary come from the style, the structural rules do not, because an H1, a lead aside, an executive summary and section headings are the shape of a grounded article rather than a matter of taste.
The default style takes the fast path — a package-level regex compiled once — so the common case pays nothing for the configurability. A custom style compiles its banned-word matcher on demand.
func Faithfulness ¶
Faithfulness cross-checks a draft against the verified claim ledger with the default policy. Hard errors (returned first) block a save; warnings are advisory.
func FaithfulnessWithOptions ¶
func FaithfulnessWithOptions(article string, records []claims.Record, opts Options) (errs, warnings []string)
FaithfulnessWithOptions is Faithfulness with an explicit policy.
func LimitationCounts ¶ added in v0.0.52
LimitationCounts is how many limitations the writer was given and how many the draft carries, for the provenance record.
func LimitationRetention ¶ added in v0.0.52
LimitationRetention checks that the draft carries the limitations its writer was given: given is the ledger the writing prompt held (see claims.SelectForPrompt), not the whole extraction. A draft that keeps none of them is an error; each one dropped is a warning.
"Carries" means what --verify reports: an article sentence attributed to the claim by provenance.Attribute. The floor is one, not all, because the measured rate is far below all: thirteen published articles carried 103 of the 310 limitations their ledgers held, and a writer given a long ledger cannot fit every caveat into one article. A draft with none, though, is presenting a source's results without the limits the source states.
func LooksLikeArticle ¶
LooksLikeArticle reports whether s resembles a Markdown article body, used to decide whether a failed draft is still worth saving for manual review.
func Paragraphs ¶
Paragraphs splits an article on blank lines, the unit the duplicate check works in. Exported so a repair pass can address the same paragraphs the check complains about, rather than re-deriving the split and drifting.
func SeparatePopulations ¶ added in v0.0.53
SeparatePopulations warns about a sentence that states numbers from two claims which look like two studies: their quotes verified in different sections and count different groups (banks in one, corporates in the other, as rules.PopulationNouns lists them). Put side by side, such numbers read as one comparison the source never made: the 2026-11-30 article set 60% of banks against 32% of corporates from two separate surveys.
It is a warning, never an error. Sections are where the reader split the source, not where its studies begin, so one section can hold two surveys and one survey can span two sections; the check is a prompt to look.
func UnsafeMarkup ¶ added in v0.0.49
UnsafeMarkup lists the constructs in md that would run script or load foreign content once a Markdown site renders it: dangerous elements, event handler attributes (in HTML or a kramdown attribute list), and javascript:, vbscript: or data: URLs in a link, image, reference definition, autolink or URL attribute. Each kind is listed once, in the order first found, so a caller can compare two drafts. An empty result means none was found.
Code spans and fences are not exempt. A renderer escapes them, but the article's text also feeds frontmatter and excerpts that strip the backticks, and an article that needs a live payload in code is not one draft writes.
func WordCount ¶
WordCount counts the words of prose a reader sees: whitespace-separated tokens that contain a letter or a digit, after HTML comments, tags and link targets are removed. "3,000", "FCA's" and "AI-driven" are one word each, and a lone "##" or dash is none. Splitting at every non-letter instead counted numbers, contractions, hyphenations and the lead aside's attributes as extra words, and put real drafts up to 171 words over their prose length.
Types ¶
type Options ¶
type Options struct {
// StrictNumbers makes a number that appears in the article and in no
// claim block the save instead of merely warning.
//
// A fabricated number is the clearest possible sign of invention, and for
// a tool whose promise is that every sentence is grounded, letting one
// reach disk with a line on stderr is hard to defend. It is opt-in for
// one release because the naive check is noisy — see ungroundedNumbers —
// so the real false-positive rate can be measured on a corpus before it
// becomes the default.
StrictNumbers bool
// StrictQuotes makes a quotation that no verified source quote contains
// block the save instead of merely warning. See unsourcedQuotations.
StrictQuotes bool
// SourceNames maps each source of a merged article to the words that
// name it in prose, for the comparison-sentence rule. Fewer than two
// sources means there is nothing to compare.
SourceNames map[string][]string
}
Options tunes the checks whose strictness is a policy choice rather than a correctness one.