parser

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package parser forgivingly extracts a JSON object from messy model output. Grammar-constrained decoding already yields valid JSON in the common case; this is the safety net for fenced blocks, leading/trailing prose, and minor defects (trailing commas, smart quotes).

Index

Constants

This section is empty.

Variables

View Source
var ErrNoJSON = errors.New("no JSON object found in output")

Functions

func Extract

func Extract(raw string) (json.RawMessage, error)

Extract returns the first valid JSON object found in raw, as compact bytes.

func StripThink

func StripThink(s string) string

StripThink removes a leading <think>…</think> reasoning span (emitted by the reasoning tier's think-prefixed grammar, see gbnf.WrapThinking) so the remainder is the bare JSON that Extract expects — needed for bare-string outputs (classify/triage enums) where the first-object-span fallback can't find the value. The grammar guarantees the output starts with "<think>" and that the FIRST "</think>" is the structural separator (the think rule forbids "</think>" inside reasoning); a later "</think>" therefore belongs to the JSON answer and must be preserved — so split on the FIRST close tag, and only when the content actually opens with <think> (a non-reasoning response that merely contains </think> is left untouched). Returns s unchanged if it is not a think-wrapped response.

Types

This section is empty.

Jump to

Keyboard shortcuts

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