package ocaml-ai-sdk
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=cb3b82428abcda76c02ec92f8103a4db28edf3f42795794a37135e9a3c40af96
sha512=11be8889ee25bee67b2be00553c42a4692bc73e5ce23985e8bb87f8a07e9d8f556b5a63b219fe5fe30366c8b0d4edae494afa80ccfbfcb112f1fa1e458de55bf
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).