Documentation
¶
Overview ¶
Package dataset is the versioned JSONL codec for eval scenarios. It is the eval framework's untrusted deserialization boundary: a dataset file is one dataset/v1 envelope per line, each carrying an explicit version discriminator and a scenario payload. The codec reads the version first and rejects unknown or missing versions before trusting the payload (fail-closed), reconstructs the conversation by discriminating each message's role, and validates every scenario against the strict eval domain types before returning it.
All sizes are bounded (MaxRecordBytes per line, MaxFileBytes per file), records load and are returned in file order, duplicate scenario IDs are rejected, and every failure is a typed error carrying only safe locators (a caller-supplied file name and a 1-based line number) — never the offending record bytes, conversation text, or tool output. Directory-scoped loading uses os.Root so a symlink or "../" in a file name cannot escape the caller-provided root.
Index ¶
- Constants
- func DecodeRecord(data []byte) (eval.Scenario, error)
- func Encode(w io.Writer, scenarios []eval.Scenario) error
- func EncodeRecord(sc eval.Scenario) ([]byte, error)
- type Dataset
- type DirectoryError
- type DuplicateScenarioError
- type EncodeError
- type FileTooLargeError
- type InvalidScenarioError
- type MalformedRecordError
- type OpenError
- type PathEscapeError
- type ReadError
- type RecordTooLargeError
- type UnknownVersionError
- type WriteError
Constants ¶
const ( // MaxRecordBytes bounds a single JSONL record (one line). MaxRecordBytes = 1 << 20 // 1 MiB // MaxFileBytes bounds a whole dataset file. MaxFileBytes = 16 << 20 // 16 MiB )
Byte bounds for the untrusted decode boundary. They reject an oversized line or file before it can exhaust memory. Conservative starting values; tune to real dataset sizes later.
Variables ¶
This section is empty.
Functions ¶
func DecodeRecord ¶
DecodeRecord decodes a single JSONL record into a validated scenario. It is the untrusted boundary and the fuzz target: for any input it returns either a valid scenario or a typed error, and never panics. Enforced in order: the per-record size bound, valid UTF-8, exactly one JSON value (no trailing data), a known version, a reconstructable conversation, and domain validation.
Types ¶
type Dataset ¶
Dataset is an ordered set of validated scenarios decoded from a dataset file. Order mirrors file order, so a dataset is reproducible.
func Decode ¶
Decode reads a JSONL dataset from r and returns its scenarios in file order. name is a safe locator used only in diagnostics. Decode enforces the file and per-record size bounds, requires each non-terminal line to be exactly one JSON value, and rejects duplicate scenario IDs.
type DirectoryError ¶
DirectoryError reports that the dataset root directory itself could not be opened. Dir is the caller-supplied (safe) directory; Cause is exposed via Unwrap.
func (*DirectoryError) Error ¶
func (e *DirectoryError) Error() string
func (*DirectoryError) Unwrap ¶
func (e *DirectoryError) Unwrap() error
type DuplicateScenarioError ¶
type DuplicateScenarioError struct {
// Line is the 1-based line of the duplicate.
Line int
// FirstLine is the 1-based line where the ID was first seen.
FirstLine int
}
DuplicateScenarioError reports that two records carried the same scenario ID, which would make two cases indistinguishable in a report and in baseline comparison. The offending ID is caller-supplied and withheld; only the safe line numbers are reported.
func (*DuplicateScenarioError) Error ¶
func (e *DuplicateScenarioError) Error() string
type EncodeError ¶
type EncodeError struct {
Cause error
}
EncodeError reports that a scenario could not be serialized to a record. Cause is exposed via Unwrap. It is a programming/input error on the encode side, not a decode-boundary failure.
func (*EncodeError) Error ¶
func (e *EncodeError) Error() string
func (*EncodeError) Unwrap ¶
func (e *EncodeError) Unwrap() error
type FileTooLargeError ¶
FileTooLargeError reports that a dataset file exceeded MaxFileBytes. Path is the caller-supplied (safe) file name.
func (*FileTooLargeError) Error ¶
func (e *FileTooLargeError) Error() string
type InvalidScenarioError ¶
InvalidScenarioError reports that a decoded record was well-formed JSON but the reconstructed scenario failed domain validation. Cause is the eval package's own typed validation error — itself free of untrusted content — and is exposed via Unwrap so callers can classify it (for example errors.As to *eval.ValidationError).
func (*InvalidScenarioError) Error ¶
func (e *InvalidScenarioError) Error() string
func (*InvalidScenarioError) Unwrap ¶
func (e *InvalidScenarioError) Unwrap() error
type MalformedRecordError ¶
MalformedRecordError reports that a record was not exactly one well-formed JSON value, or that its conversation could not be reconstructed. Reason is drawn only from the fixed vocabulary above, so no untrusted content leaks.
func (*MalformedRecordError) Error ¶
func (e *MalformedRecordError) Error() string
type OpenError ¶
OpenError reports that a file under the root could not be opened for a reason other than a root escape (it does not exist, or permission was denied). Path is the caller-supplied (safe) name; Cause is exposed via Unwrap.
type PathEscapeError ¶
PathEscapeError reports that a file name resolved outside the caller-provided root directory — for example via a symlink or a "../" traversal — and was refused by the os.Root-scoped loader. Path is the caller-supplied (safe) name; Cause is the underlying os error, exposed via Unwrap but never rendered.
func (*PathEscapeError) Error ¶
func (e *PathEscapeError) Error() string
func (*PathEscapeError) Unwrap ¶
func (e *PathEscapeError) Unwrap() error
type ReadError ¶
ReadError reports that reading the dataset file failed partway through. Path is the caller-supplied (safe) name; Cause is exposed via Unwrap.
type RecordTooLargeError ¶
RecordTooLargeError reports that a single record exceeded MaxRecordBytes. Only safe integers are carried; no record content is embedded.
func (*RecordTooLargeError) Error ¶
func (e *RecordTooLargeError) Error() string
type UnknownVersionError ¶
type UnknownVersionError struct {
// Line is the 1-based record line, or 0 when decoded standalone.
Line int
// Version is a bounded, safe rendering of the offending token, or "" when
// it was missing or withheld.
Version string
}
UnknownVersionError reports that a record's version discriminator was missing or names a wire version this codec does not implement. The version token may originate from untrusted input, so it is bounded and withheld when hostile; Version is either a short, valid token or "" when redacted.
func (*UnknownVersionError) Error ¶
func (e *UnknownVersionError) Error() string
type WriteError ¶
type WriteError struct {
Cause error
}
WriteError reports that writing an encoded record to the output stream failed. Cause is exposed via Unwrap.
func (*WriteError) Error ¶
func (e *WriteError) Error() string
func (*WriteError) Unwrap ¶
func (e *WriteError) Unwrap() error