schema

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 7 Imported by: 3

Documentation

Overview

Package schema provides embedded PromptPack schema for offline validation.

promptpack.schema.json is a verbatim mirror — never edit it

The embedded promptpack.schema.json is a byte-for-byte copy of the published PromptPack release at https://promptpack.org/schema/latest/. PromptKit does not own it and must never hand-edit it: not to add a field the runtime wants, not to delete one the runtime doesn't implement, not to tighten an enum the spec leaves open.

The only sanctioned way to change it is scripts/fetch-promptpack-schema.sh (make promptpack-schema). CI fails on any difference (make promptpack-schema-check).

Where the runtime deliberately declines to carry a spec property, record it as a deliberateOmission in runtime/prompt/validator_spec_parity_test.go, in Go, where a reviewer sees it. Editing the schema to make a parity test pass makes the guard circular — it grades promptkit's types against a document promptkit edits — and that is exactly how this file drifted 143 leaves from the spec between 2026-06 and 2026-08 while still claiming to be v1.5.0, silently rejecting packs that were valid against promptpack.org.

Package schema provides embedded PromptPack schema and shared schema validation utilities.

Index

Constants

View Source
const DefaultSchemaURL = "https://promptpack.org/schema/latest/promptpack.schema.json"

DefaultSchemaURL is the canonical URL for the PromptPack schema.

View Source
const SchemaSourceEnvVar = "PROMPTKIT_SCHEMA_SOURCE"

SchemaSourceEnvVar is the environment variable to override schema source. Values: "local" (embedded), "remote" (fetch from URL), or a file path.

Variables

This section is empty.

Functions

func ExtractSchemaURL

func ExtractSchemaURL(packJSON []byte) string

ExtractSchemaURL extracts the $schema URL from pack JSON data. Returns empty string if not present or invalid.

func GetEmbeddedSchema

func GetEmbeddedSchema() string

GetEmbeddedSchema returns the embedded schema as a string.

func GetEmbeddedSchemaVersion

func GetEmbeddedSchemaVersion() (string, error)

GetEmbeddedSchemaVersion returns the version from the embedded schema.

func GetSchemaLoader

func GetSchemaLoader(packSchemaURL string) (gojsonschema.JSONLoader, error)

GetSchemaLoader returns a gojsonschema loader for the PromptPack schema. Priority:

  1. If PROMPTKIT_SCHEMA_SOURCE is set to "local", use embedded schema
  2. If PROMPTKIT_SCHEMA_SOURCE is a file path, load from that file
  3. If PROMPTKIT_SCHEMA_SOURCE is "remote" and packSchemaURL is provided, fetch from that URL
  4. Otherwise, use embedded schema (default for offline support)

func LookupEnumValues added in v1.4.12

func LookupEnumValues(root map[string]any, fieldPath string) []string

LookupEnumValues is the exported wrapper for cross-package callers.

func LookupProperties added in v1.4.12

func LookupProperties(root map[string]any, fieldPath string) []string

LookupProperties is the exported wrapper for cross-package callers.

func NearestMatches added in v1.4.12

func NearestMatches(target string, candidates []string) []string

NearestMatches is the exported wrapper for cross-package callers.

Types

type ValidationError added in v1.3.2

type ValidationError struct {
	Field       string
	Description string
	Value       interface{}

	// Keyword is the JSON-schema keyword that failed (e.g. "enum",
	// "additional_property_not_allowed", "required"). Sourced from
	// gojsonschema's ResultError.Type(). Empty if unavailable.
	Keyword string
	// ValidValues lists allowed values when computable. Populated by
	// higher-level callers that hold the raw schema document. Nil when
	// not enumerable at this layer.
	ValidValues []string
	// Suggestions are nearest-match candidates from ValidValues.
	Suggestions []string
}

ValidationError represents a single schema validation error with field-level detail.

func (ValidationError) Error added in v1.3.2

func (e ValidationError) Error() string

Error implements the error interface.

type ValidationResult added in v1.3.2

type ValidationResult struct {
	Valid  bool
	Errors []ValidationError
}

ValidationResult contains the results of JSON schema validation.

func ConvertResult added in v1.3.2

func ConvertResult(result *gojsonschema.Result) *ValidationResult

ConvertResult converts a gojsonschema result into a ValidationResult.

func ValidateJSONAgainstLoader added in v1.3.2

func ValidateJSONAgainstLoader(jsonData []byte, schemaLoader gojsonschema.JSONLoader) (*ValidationResult, error)

ValidateJSONAgainstLoader validates raw JSON bytes against a schema provided as a gojsonschema.JSONLoader. This is the shared, low-level validation entry point used by Arena config validation (pkg/config), PromptPack validation (sdk/internal/pack), and the pack compiler (PackC).

Jump to

Keyboard shortcuts

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