JsonlCodec

org.llm4s.eval.dataset.JsonlCodec
object JsonlCodec

Codec for reading and writing Example values as JSONL (newline-delimited JSON).

Each line produced by encode is a compact, single-line JSON object. decode is the inverse: it parses one such line back into an Example, returning None for any malformed or structurally invalid input without throwing.

Intended for batch import/export via DatasetStore.importJsonl and DatasetStore.exportJsonl.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
JsonlCodec.type

Members list

Value members

Concrete methods

def decode(line: String): Option[Example[Value, Value]]

Attempts to parse a single JSONL line into an Example.

Attempts to parse a single JSONL line into an Example.

Returns None if:

  • line is not valid JSON
  • the top-level value is not a JSON object
  • the required id or input fields are absent or have the wrong type

Optional-field behaviour:

  • referenceOutput: JSON nullNone; any other value → Some(value)
  • tags: absent or non-array → empty Set
  • metadata: absent or non-object → empty Map; non-string values coerced to ""

Never throws; all parse errors are caught and collapsed to None.

Attributes

def encode(example: Example[Value, Value]): String

Serialises an Example to a compact, single-line JSON string.

Serialises an Example to a compact, single-line JSON string.

Field mapping:

  • id — the ExampleId value as a string
  • input — the input ujson.Value verbatim
  • referenceOutput — the output ujson.Value, or JSON null when None
  • tags — JSON array of tag strings
  • metadata — JSON object with string values

The result never contains newline characters and is safe to use as a single JSONL record.

Attributes