package ocaml-ai-sdk
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=636d458cb1564ed88ca8c0250c432e91c2f822fd49ad2b923819e762bda10be6
sha512=361e476423ebc0f9cf561cc28ccd4531cf08e424e95eea43a67d6b8dbb457a49a25b418625ffa99f6327fc5df14e540e502d1aa8ed606111c5c010fe498eec2a
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).