1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Helpers for turning Rust type information into JSON Schema that can be
//! shipped alongside a prompt. The JSON is produced with [`schemars`] and
//! can be forwarded to providers that support structured / function-calling
//! responses (e.g. OpenAI’s *response_format = json_schema*).
//!
//! The abstraction is intentionally **very small**: if you need a more
//! sophisticated setup (e.g. inline- vs. $ref-based schemas, custom
//! serialization logic) you can always bypass this helper and build the
//! schema manually.
use ;
use ;
/// Generate a JSON Schema for the given `T` **inline**, i.e. without
/// `$ref` pointers to external definitions.
///
/// This is sufficient for most LLM providers, which currently expect the
/// entire schema object inside a single request.
///
/// # Panics
///
/// This function panics only if the resulting [`RootSchema`] cannot be
/// serialized into valid JSON – which should never happen as long as
/// [`schemars`] works correctly.
///
/// # Example
///
/// ```
/// use artificial_core::schema_util::derive_response_schema;
/// use schemars::JsonSchema;
///
/// #[derive(JsonSchema)]
/// struct Foo { bar: String }
///
/// let schema = derive_response_schema::<Foo>();
/// println!("{}", serde_json::to_string_pretty(&schema).unwrap());
/// ```