package ocaml-ai-sdk
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=637f60398f673dfb2e661f6ed7da169b823a870d27b48e729d5b9200e46a52b2
sha512=5aec259473395025edb6689b544e57e821cfbef9352987f95eb2182034979ce898040e06e60a9d89a40a187b77fb5b1b7183c7ec4264da9d9a834864860a5fed
doc/ocaml-ai-sdk.ai_core/Ai_core/Output/index.html
Module Ai_core.OutputSource
Structured output API for generate_text and stream_text.
Matches the Vercel AI SDK v6 Output API: Output.text, Output.object_, Output.array, Output.choice. Controls model response format and adds parsing/validation.
type ('complete, 'partial) t = {name : string;response_format : Ai_provider.Mode.json_schema option;(*Schema to pass to the provider via
*)Mode.Object_json.Nonemeans text mode (no JSON instruction).parse_complete : string -> ('complete, string) result;(*Parse and validate the complete model response text. Returns
*)Error msgif JSON parsing or schema validation fails.parse_partial : string -> 'partial option;(*Parse a potentially incomplete response for streaming. Returns
*)Noneif text is empty or unparseable. No schema validation.
}An output specification parameterized by the parsed output type.
'completeis the type returned byparse_complete(final validated output)'partialis the type returned byparse_partial(streaming partial output)
Derive the provider Mode.t from an optional output spec. Some o with a schema maps to Object_json; otherwise Regular.
val parse_output :
(Yojson.Basic.t, _) t option ->
Generate_text_result.step list ->
Yojson.Basic.t optionParse the final output from completed steps. Returns None if no output spec, text mode, or parse failure.
val object_ :
name:string ->
schema:Yojson.Basic.t ->
unit ->
(Yojson.Basic.t, Yojson.Basic.t) tObject output — model produces JSON matching the given schema. name is passed to the provider for context. Complete output is validated against the schema. Partial output uses repair-and-parse (no validation).
val array :
name:string ->
element_schema:Yojson.Basic.t ->
unit ->
(Yojson.Basic.t, Yojson.Basic.t) tArray output — model produces an array of elements matching the schema. Wraps in {"elements":[...]} envelope for the model, unwraps on parse. Complete output validates every element against the schema. Partial output drops the last element on repaired parses and silently skips invalid elements.
Choice output — model picks one of the given string options. Wraps in {"result":"..."} envelope for the model, unwraps on parse. Complete output validates the choice is in the allowed list. Partial output uses prefix matching: on repaired parses, only returns when exactly one option matches the prefix (unambiguous).