OCaml Claude SDK using Eio and Jsont
at main 67 lines 2.4 kB view raw
1(*--------------------------------------------------------------------------- 2 Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 SPDX-License-Identifier: ISC 4 ---------------------------------------------------------------------------*) 5 6(** Structured output configuration using JSON Schema. 7 8 This module provides the wire format types for structured output support, 9 allowing specification of expected output formats using JSON schemas. When a 10 structured output format is configured, Claude will return its response in 11 the specified JSON format, validated against the provided schema. 12 13 This is the protocol-level module. For the high-level API with logging and 14 additional features, see {!Claude.Structured_output}. *) 15 16(** {1 Output Format Configuration} *) 17 18type t 19(** The type of structured output format configurations. 20 21 This wraps a JSON Schema that specifies the expected output format. *) 22 23val of_json_schema : Jsont.json -> t 24(** [of_json_schema schema] creates an output format from a JSON Schema. 25 26 The schema should be a valid JSON Schema Draft 7 as a {!type:Jsont.json} 27 value. 28 29 Example: 30 {[ 31 let meta = Jsont.Meta.none in 32 let schema = 33 Jsont.Object 34 ( [ 35 (("type", meta), Jsont.String ("object", meta)); 36 ( ("properties", meta), 37 Jsont.Object 38 ( [ 39 ( ("name", meta), 40 Jsont.Object 41 ([ (("type", meta), Jsont.String ("string", meta)) ], meta) 42 ); 43 ( ("age", meta), 44 Jsont.Object 45 ([ (("type", meta), Jsont.String ("integer", meta)) ], meta) 46 ); 47 ], 48 meta ) ); 49 ( ("required", meta), 50 Jsont.Array 51 ([ Jsont.String ("name", meta); Jsont.String ("age", meta) ], meta) 52 ); 53 ], 54 meta ) 55 in 56 57 let format = Structured_output.of_json_schema schema 58 ]} *) 59 60val to_json_schema : t -> Jsont.json 61(** [to_json_schema t] extracts the JSON Schema from the output format. *) 62 63val jsont : t Jsont.t 64(** Codec for structured output format. 65 66 Encodes/decodes the structured output configuration to/from the wire format 67 JSON representation used by the Claude CLI protocol. *)