gleamunison/sap

Schema-Aligned Parsing (gap analysis concept B).

Liberal-in-what-you-accept repair of near-miss model output: fences, yapping, comments, trailing commas, single quotes, unquoted keys, Python literals — then strict decode, then validation against a JSON-native Schema (bridged from core ast.Type). Pure Gleam, no FFI.

Types

pub type SapError {
  NoJsonFound
  StrictError(reason: String)
  ValidationFailed(paths: List(String))
}

Constructors

  • NoJsonFound
  • StrictError(reason: String)
  • ValidationFailed(paths: List(String))
pub type Schema {
  SAny
  SInt
  SFloat
  SText
  SBool
  SList(of: Schema)
  SObj(fields: List(#(String, Schema)), required: List(String))
  SEnum(values: List(String))
}

Constructors

  • SAny
  • SInt
  • SFloat
  • SText
  • SBool
  • SList(of: Schema)
  • SObj(fields: List(#(String, Schema)), required: List(String))
  • SEnum(values: List(String))

Values

pub fn decode_as(
  text: String,
  schema: Schema,
) -> Result(dynamic.Dynamic, SapError)

Repair, decode, and validate against a schema.

pub fn parse(text: String) -> Result(String, SapError)

Repair near-miss model output into strict JSON text.

pub fn schema_from_type(t: ast.Type) -> Schema

Bridge from core types; unresolved constructors degrade to SAny.

✨ Search Document