Help us shape the future of Go! Take the 2026 Go Developer Survey

validate

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(raw string, lineCount int) (*schema.Report, error)

Parse strips markdown fences, unmarshals JSON, and validates the structure of an LLM response. lineCount is the number of lines in the spec file and is used to validate evidence bounds.

func ParseReport added in v0.3.0

func ParseReport(raw []byte) (*schema.Report, error)

ParseReport reads a JSON report that SpecCritic wrote, for use as the baseline of a later run. It holds the report to what SpecCritic writes, which is not what Parse and ParseResponse ask of a model:

  • A finding tagged "preflight" may carry its rule ID (PREFLIGHT-<GROUP>-<NNN>) in place of an ISSUE number, and several findings may share one rule ID because a rule can match more than once. Every other issue needs an ISSUE number of its own.
  • An evidence path is a label for display and is not checked. Reports written before preflight evidence used schema.EvidencePath hold the spec path as it was given, which may be absolute.
  • Patches are not checked. Nothing reads the patches of a baseline, and a report filtered by --severity-threshold can keep a patch whose issue was filtered out.

func StripFences added in v0.3.0

func StripFences(s string) string

StripFences removes a Markdown code fence wrapped around a JSON response.

Types

type Options added in v0.3.0

type Options struct {
	// LineCount is the number of lines in the spec; evidence must stay inside it.
	LineCount int
	// SpecPath, when set, replaces the path on every evidence entry. The caller
	// knows which file was reviewed, so the model's copy is not used. The path
	// is spelled by schema.EvidencePath, so evidence paths always pass the
	// check Parse applies.
	SpecPath string
	// SpecText, when set, is the spec as the model was shown it. Every quote
	// is then looked up in it: evidence is moved to where its quote really is,
	// quotes are replaced by the spec's exact text, an issue whose quotes are
	// nowhere in the spec is tagged and cannot stay CRITICAL, and an issue with
	// no evidence at all is dropped. See package evidence.
	SpecText string
	// CheckIssue and CheckQuestion apply caller-specific rules to a finding
	// that passed the general checks, and may adjust it. They run after
	// evidence has been checked, so they see corrected line ranges. A non-nil
	// error drops the finding.
	CheckIssue    func(*schema.Issue) error
	CheckQuestion func(*schema.Question) error
	// ExtraFields names top-level fields beyond issues, questions and patches
	// that the caller wants. Each one found whole is returned in Result.Extra.
	ExtraFields []string
}

Options controls how a model response is checked.

type Result added in v0.3.0

type Result struct {
	Report *schema.Report
	// Incomplete is non-nil when the JSON ended early or broke mid-document.
	// Report then holds only the findings that were read before that point.
	Incomplete error
	// Dropped explains each finding that failed validation and was left out.
	Dropped []string
	// Extra holds the fields named in Options.ExtraFields that were read whole.
	Extra map[string]json.RawMessage
}

Result is the usable part of a model response.

func ParseResponse added in v0.3.0

func ParseResponse(raw string, opts Options) (Result, error)

ParseResponse reads a model response one finding at a time. A finding that fails validation is dropped and the rest are kept, and a response cut off at the output cap still yields the findings that arrived whole. It returns an error only when the response holds nothing usable.

IDs are returned as the model wrote them, so they may be malformed or repeated; llm.CompleteReport renumbers them. Patches are not matched to issues here, because a patch in a continued response may point at an issue from an earlier part.

Parse, by contrast, needs the whole document to be valid.

Jump to

Keyboard shortcuts

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