typia 12.0.1 → 12.1.0-dev.20260325

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/llm.ts CHANGED
@@ -1,480 +1,480 @@
1
- import {
2
- IJsonParseResult,
3
- ILlmApplication,
4
- ILlmController,
5
- ILlmSchema,
6
- ILlmStructuredOutput,
7
- } from "@typia/interface";
8
-
9
- import { NoTransformConfigurationError } from "./transformers/NoTransformConfigurationError";
10
-
11
- /* -----------------------------------------------------------
12
- FUNCTION CALLING
13
- ----------------------------------------------------------- */
14
- /**
15
- * Creates LLM function calling controller.
16
- *
17
- * @danger You must configure the generic argument `Class`
18
- */
19
- export function controller(
20
- name: string,
21
- execute: object,
22
- config?: Partial<Pick<ILlmApplication.IConfig<any>, "validate">>,
23
- ): never;
24
-
25
- /**
26
- * Creates LLM function calling controller from class/interface.
27
- *
28
- * Generates {@link ILlmController} from a TypeScript class or interface,
29
- * containing both function calling schemas ({@link ILlmFunction}) and an
30
- * executor ({@link ILlmController.execute}).
31
- *
32
- * Each {@link ILlmFunction} includes a built-in {@link ILlmFunction.validate}
33
- * function that validates LLM-generated arguments before execution. When
34
- * validation fails, use `LlmJson.stringify()` from `@typia/utils` to format
35
- * errors for LLM feedback, enabling auto-correction.
36
- *
37
- * When passed to LLM providers (ChatGPT, Claude, Gemini, etc.), the LLM
38
- * automatically selects functions and fills arguments from conversation.
39
- * Execute the selected function via {@link ILlmController.execute}.
40
- *
41
- * Related functions:
42
- *
43
- * - {@link application} — Schemas only, without executor
44
- * - {@link parameters} — Single parameters schema for structured output
45
- * - {@link schema} — Single type schema
46
- *
47
- * @template Class Target class or interface type
48
- * @template Config LLM schema configuration
49
- * @param name Controller identifier name
50
- * @param execute Executor instance
51
- * @param config LLM application options
52
- * @returns LLM function calling controller
53
- */
54
- export function controller<
55
- Class extends Record<string, any>,
56
- Config extends Partial<
57
- ILlmSchema.IConfig & {
58
- /**
59
- * Whether to disallow superfluous properties or not.
60
- *
61
- * If configure as `true`, {@link validateEquals} function would be used
62
- * for validation feedback, which is more strict than {@link validate}
63
- * function.
64
- *
65
- * @default false
66
- */
67
- equals: boolean;
68
- }
69
- > = {},
70
- >(
71
- name: string,
72
- execute: Class,
73
- config?: Partial<Pick<ILlmApplication.IConfig<Class>, "validate">>,
74
- ): ILlmController<Class>;
75
-
76
- /** @internal */
77
- export function controller(..._args: any[]): never {
78
- NoTransformConfigurationError("llm.controller");
79
- }
80
-
81
- /**
82
- * Creates LLM function calling application.
83
- *
84
- * @danger You must configure the generic argument `Class`
85
- */
86
- export function application(
87
- config?: Partial<Pick<ILlmApplication.IConfig<any>, "validate">>,
88
- ): never;
89
-
90
- /**
91
- * Creates LLM function calling application from class/interface.
92
- *
93
- * Generates {@link ILlmApplication} from a TypeScript class or interface,
94
- * containing function calling schemas ({@link ILlmFunction}). Does not include
95
- * an executor—use {@link controller} if you need execution capability.
96
- *
97
- * Each {@link ILlmFunction} includes a built-in {@link ILlmFunction.validate}
98
- * function that validates LLM-generated arguments before execution. When
99
- * validation fails, use `LlmJson.stringify()` from `@typia/utils` to format
100
- * errors for LLM feedback, enabling auto-correction.
101
- *
102
- * When passed to LLM providers (ChatGPT, Claude, Gemini, etc.), the LLM
103
- * automatically selects functions and fills arguments from conversation. You
104
- * execute the function manually with the LLM-prepared arguments.
105
- *
106
- * Related functions:
107
- *
108
- * - {@link controller} — Includes executor alongside schemas
109
- * - {@link parameters} — Single parameters schema for structured output
110
- * - {@link schema} — Single type schema
111
- *
112
- * @template Class Target class or interface type
113
- * @template Config LLM schema configuration
114
- * @param config LLM application options
115
- * @returns LLM function calling application
116
- */
117
- export function application<
118
- Class extends Record<string, any>,
119
- Config extends Partial<
120
- ILlmSchema.IConfig & {
121
- /**
122
- * Whether to disallow superfluous properties or not.
123
- *
124
- * If configure as `true`, {@link validateEquals} function would be used
125
- * for validation feedback, which is more strict than {@link validate}
126
- * function.
127
- *
128
- * @default false
129
- */
130
- equals: boolean;
131
- }
132
- > = {},
133
- >(
134
- config?: Partial<Pick<ILlmApplication.IConfig<Class>, "validate">>,
135
- ): ILlmApplication<Class>;
136
-
137
- /** @internal */
138
- export function application(): never {
139
- NoTransformConfigurationError("llm.application");
140
- }
141
-
142
- /**
143
- * Creates LLM structured output interface.
144
- *
145
- * @danger You must configure the generic argument `T`
146
- */
147
- export function structuredOutput(): never;
148
-
149
- /**
150
- * Creates LLM structured output interface from TypeScript object type.
151
- *
152
- * Generates {@link ILlmStructuredOutput} containing everything needed for
153
- * handling LLM structured outputs: the JSON schema for prompting, and functions
154
- * for parsing, coercing, and validating responses.
155
- *
156
- * Structured outputs allow LLMs to generate data conforming to a predefined
157
- * schema instead of free-form text. This is useful for:
158
- *
159
- * - Extracting structured data from conversations
160
- * - Generating typed responses for downstream processing
161
- * - Ensuring consistent output formats across LLM calls
162
- *
163
- * Workflow:
164
- *
165
- * 1. Pass {@link ILlmStructuredOutput.parameters} schema to LLM provider
166
- * 2. Receive LLM response (JSON string or pre-parsed object)
167
- * 3. Use {@link ILlmStructuredOutput.parse} for raw strings or
168
- * {@link ILlmStructuredOutput.coerce} for pre-parsed objects
169
- * 4. Use {@link ILlmStructuredOutput.validate} to check the result
170
- *
171
- * Related functions:
172
- *
173
- * - {@link parameters} — Schema only, without parse/coerce/validate
174
- * - {@link application} — Multiple function schemas from class/interface
175
- * - {@link controller} — Application with executor
176
- *
177
- * @template T Target output type (object with static properties)
178
- * @template Config LLM schema configuration
179
- * @returns LLM structured output interface
180
- */
181
- export function structuredOutput<
182
- T extends Record<string, any>,
183
- Config extends Partial<
184
- ILlmSchema.IConfig & {
185
- /**
186
- * Whether to disallow superfluous properties or not.
187
- *
188
- * If configure as `true`, {@link validateEquals} function would be used
189
- * for validation feedback, which is more strict than {@link validate}
190
- * function.
191
- *
192
- * @default false
193
- */
194
- equals: boolean;
195
- }
196
- > = {},
197
- >(): ILlmStructuredOutput<T>;
198
-
199
- /** @internal */
200
- export function structuredOutput(): never {
201
- NoTransformConfigurationError("llm.structuredOutput");
202
- }
203
-
204
- /* -----------------------------------------------------------
205
- RAW SCHEMAS
206
- ----------------------------------------------------------- */
207
- /**
208
- * Creates LLM parameters schema.
209
- *
210
- * @danger You must configure the generic argument `Parameters`
211
- */
212
- export function parameters(): never;
213
-
214
- /**
215
- * Creates LLM parameters schema from TypeScript object type.
216
- *
217
- * Generates {@link ILlmSchema.IParameters} for LLM function calling or
218
- * structured outputs. LLMs use keyworded arguments only, so the type must be an
219
- * object with static properties (no dynamic properties allowed).
220
- *
221
- * Use cases:
222
- *
223
- * - Function calling: LLM fills parameters from conversation
224
- * - Structured outputs: LLM generates structured data, not plain text
225
- *
226
- * Related functions:
227
- *
228
- * - {@link application} — Multiple function schemas from class/interface
229
- * - {@link controller} — Application with executor
230
- * - {@link schema} — Single type schema (not parameters-specific)
231
- *
232
- * @template Parameters Target parameters type (object with static properties)
233
- * @template Config LLM schema configuration
234
- * @returns LLM parameters schema
235
- */
236
- export function parameters<
237
- Parameters extends Record<string, any>,
238
- Config extends Partial<ILlmSchema.IConfig> = {},
239
- >(): ILlmSchema.IParameters;
240
-
241
- /** @internal */
242
- export function parameters(): never {
243
- NoTransformConfigurationError("llm.parameters");
244
- }
245
-
246
- /**
247
- * Creates LLM type schema.
248
- *
249
- * @danger You must configure the generic argument `T`
250
- */
251
- export function schema(): never;
252
-
253
- /**
254
- * Creates LLM type schema from TypeScript type.
255
- *
256
- * Generates {@link ILlmSchema} for use in LLM function calling. For actual
257
- * function calling with TypeScript functions, use {@link application}. For
258
- * structured output generation, use {@link parameters}.
259
- *
260
- * LLM function calling flow:
261
- *
262
- * 1. LLM selects function and fills arguments from conversation
263
- * 2. You execute the function with LLM-prepared arguments
264
- * 3. Return value is passed back to LLM via system prompt
265
- * 4. LLM continues conversation based on return value
266
- *
267
- * Related functions:
268
- *
269
- * - {@link application} — Multiple function schemas from class/interface
270
- * - {@link controller} — Application with executor
271
- * - {@link parameters} — Parameters schema for structured output
272
- *
273
- * @template T Target type
274
- * @template Config LLM schema configuration
275
- * @param $defs Shared schema definitions for `$ref` referencing
276
- * @returns LLM type schema
277
- */
278
- export function schema<T, Config extends Partial<ILlmSchema.IConfig> = {}>(
279
- $defs: Record<string, ILlmSchema>,
280
- ): ILlmSchema;
281
-
282
- /** @internal */
283
- export function schema(): never {
284
- NoTransformConfigurationError("llm.schema");
285
- }
286
-
287
- /* -----------------------------------------------------------
288
- UTILITY FUNCTIONS
289
- ----------------------------------------------------------- */
290
- /**
291
- * Parse LLM response JSON with type coercion.
292
- *
293
- * @danger You must configure the generic argument `Parameters`
294
- */
295
- export function parse(input: string): never;
296
-
297
- /**
298
- * Parse lenient JSON with schema-based type coercion.
299
- *
300
- * Handles incomplete or malformed JSON commonly produced by LLMs:
301
- *
302
- * - Unclosed brackets, strings, trailing commas
303
- * - JavaScript-style comments (`//` and multi-line)
304
- * - Unquoted object keys, incomplete keywords (`tru`, `fal`, `nul`)
305
- * - Markdown code block extraction, junk prefix skipping
306
- *
307
- * Also coerces double-stringified values based on the `Parameters` schema:
308
- *
309
- * - `"42"` → `42` (when schema expects number)
310
- * - `"true"` → `true` (when schema expects boolean)
311
- * - `"null"` → `null` (when schema expects null)
312
- * - `"{...}"` → `{...}` (when schema expects object)
313
- * - `"[...]"` → `[...]` (when schema expects array)
314
- *
315
- * Type validation is NOT performed—use {@link ILlmFunction.validate} or
316
- * `typia.validate()` for that.
317
- *
318
- * For repeated parsing, use {@link createParse} to avoid regenerating the schema
319
- * each time.
320
- *
321
- * Related functions:
322
- *
323
- * - {@link createParse} — Create reusable parser function
324
- * - {@link coerce} — Type coercion for already-parsed objects
325
- * - {@link parameters} — Generate parameters schema from type
326
- *
327
- * @template Parameters Target parameters type (object with static properties)
328
- * @template Config LLM schema configuration
329
- * @param input Raw JSON string (potentially incomplete or malformed)
330
- * @returns Parse result with typed data on success, or partial data with errors
331
- */
332
- export function parse<
333
- Parameters extends Record<string, any>,
334
- Config extends Partial<ILlmSchema.IConfig> = {},
335
- >(input: string): IJsonParseResult<Parameters>;
336
-
337
- /** @internal */
338
- export function parse(): never {
339
- NoTransformConfigurationError("llm.parse");
340
- }
341
-
342
- /**
343
- * Coerce LLM arguments to match expected schema types.
344
- *
345
- * LLMs often return values with incorrect types (e.g., numbers as strings).
346
- * This function recursively coerces values based on the `Parameters` schema:
347
- *
348
- * - `"42"` → `42` (when schema expects number)
349
- * - `"true"` → `true` (when schema expects boolean)
350
- * - `"null"` → `null` (when schema expects null)
351
- * - `"{...}"` → `{...}` (when schema expects object)
352
- * - `"[...]"` → `[...]` (when schema expects array)
353
- *
354
- * Use this when your SDK provides already-parsed objects but values may have
355
- * wrong types. For raw JSON strings, use {@link parse} instead.
356
- *
357
- * For repeated coercion, use {@link createCoerce} to avoid regenerating the
358
- * schema each time.
359
- *
360
- * Type validation is NOT performed—use {@link ILlmFunction.validate} or
361
- * `typia.validate()` for that.
362
- *
363
- * Related functions:
364
- *
365
- * - {@link createCoerce} — Create reusable coercer function
366
- * - {@link parse} — Parse and coerce raw JSON strings
367
- * - {@link parameters} — Generate parameters schema from type
368
- *
369
- * @template Parameters Target parameters type (object with static properties)
370
- * @template Config LLM schema configuration
371
- * @param input Parsed arguments object from LLM (with potentially wrong types)
372
- * @returns Coerced arguments with corrected types
373
- */
374
- export function coerce<
375
- Parameters extends Record<string, any>,
376
- Config extends Partial<ILlmSchema.IConfig> = {},
377
- >(input: Parameters): Parameters;
378
-
379
- /** @internal */
380
- export function coerce(): never {
381
- NoTransformConfigurationError("llm.coerce");
382
- }
383
-
384
- /**
385
- * Create reusable LLM JSON parser with type coercion.
386
- *
387
- * @danger You must configure the generic argument `Parameters`
388
- */
389
- export function createParse(): never;
390
-
391
- /**
392
- * Create reusable lenient JSON parser with schema-based type coercion.
393
- *
394
- * Returns a parser function that handles incomplete or malformed JSON commonly
395
- * produced by LLMs:
396
- *
397
- * - Unclosed brackets, strings, trailing commas
398
- * - JavaScript-style comments (`//` and multi-line)
399
- * - Unquoted object keys, incomplete keywords (`tru`, `fal`, `nul`)
400
- * - Markdown code block extraction, junk prefix skipping
401
- *
402
- * Also coerces double-stringified values based on the `Parameters` schema:
403
- *
404
- * - `"42"` → `42` (when schema expects number)
405
- * - `"true"` → `true` (when schema expects boolean)
406
- * - `"null"` → `null` (when schema expects null)
407
- * - `"{...}"` → `{...}` (when schema expects object)
408
- * - `"[...]"` → `[...]` (when schema expects array)
409
- *
410
- * Use this instead of {@link parse} when parsing multiple inputs to avoid
411
- * regenerating the schema each time.
412
- *
413
- * Type validation is NOT performed—use {@link ILlmFunction.validate} or
414
- * `typia.validate()` for that.
415
- *
416
- * Related functions:
417
- *
418
- * - {@link parse} — One-shot parsing (regenerates schema each call)
419
- * - {@link createCoerce} — Create reusable coercer function
420
- * - {@link parameters} — Generate parameters schema from type
421
- *
422
- * @template Parameters Target parameters type (object with static properties)
423
- * @template Config LLM schema configuration
424
- * @returns Reusable parser function
425
- */
426
- export function createParse<
427
- Parameters extends Record<string, any>,
428
- Config extends Partial<ILlmSchema.IConfig> = {},
429
- >(): (input: string) => IJsonParseResult<Parameters>;
430
-
431
- /** @internal */
432
- export function createParse(): never {
433
- NoTransformConfigurationError("llm.createParse");
434
- }
435
-
436
- /**
437
- * Create reusable LLM arguments coercer.
438
- *
439
- * @danger You must configure the generic argument `Parameters`
440
- */
441
- export function createCoerce(): never;
442
-
443
- /**
444
- * Create reusable coercer for LLM arguments.
445
- *
446
- * Returns a coercer function that fixes incorrect types commonly returned by
447
- * LLMs (e.g., numbers as strings). Coerces values based on the `Parameters`
448
- * schema:
449
- *
450
- * - `"42"` → `42` (when schema expects number)
451
- * - `"true"` → `true` (when schema expects boolean)
452
- * - `"null"` → `null` (when schema expects null)
453
- * - `"{...}"` → `{...}` (when schema expects object)
454
- * - `"[...]"` → `[...]` (when schema expects array)
455
- *
456
- * Use this instead of {@link coerce} when coercing multiple inputs to avoid
457
- * regenerating the schema each time.
458
- *
459
- * Type validation is NOT performed—use {@link ILlmFunction.validate} or
460
- * `typia.validate()` for that.
461
- *
462
- * Related functions:
463
- *
464
- * - {@link coerce} — One-shot coercion (regenerates schema each call)
465
- * - {@link createParse} — Create reusable parser function
466
- * - {@link parameters} — Generate parameters schema from type
467
- *
468
- * @template Parameters Target parameters type (object with static properties)
469
- * @template Config LLM schema configuration
470
- * @returns Reusable coercer function
471
- */
472
- export function createCoerce<
473
- Parameters extends Record<string, any>,
474
- Config extends Partial<ILlmSchema.IConfig> = {},
475
- >(): (input: Parameters) => Parameters;
476
-
477
- /** @internal */
478
- export function createCoerce(): never {
479
- NoTransformConfigurationError("llm.createCoerce");
480
- }
1
+ import {
2
+ IJsonParseResult,
3
+ ILlmApplication,
4
+ ILlmController,
5
+ ILlmSchema,
6
+ ILlmStructuredOutput,
7
+ } from "@typia/interface";
8
+
9
+ import { NoTransformConfigurationError } from "./transformers/NoTransformConfigurationError";
10
+
11
+ /* -----------------------------------------------------------
12
+ FUNCTION CALLING
13
+ ----------------------------------------------------------- */
14
+ /**
15
+ * Creates LLM function calling controller.
16
+ *
17
+ * @danger You must configure the generic argument `Class`
18
+ */
19
+ export function controller(
20
+ name: string,
21
+ execute: object,
22
+ config?: Partial<Pick<ILlmApplication.IConfig<any>, "validate">>,
23
+ ): never;
24
+
25
+ /**
26
+ * Creates LLM function calling controller from class/interface.
27
+ *
28
+ * Generates {@link ILlmController} from a TypeScript class or interface,
29
+ * containing both function calling schemas ({@link ILlmFunction}) and an
30
+ * executor ({@link ILlmController.execute}).
31
+ *
32
+ * Each {@link ILlmFunction} includes a built-in {@link ILlmFunction.validate}
33
+ * function that validates LLM-generated arguments before execution. When
34
+ * validation fails, use `LlmJson.stringify()` from `@typia/utils` to format
35
+ * errors for LLM feedback, enabling auto-correction.
36
+ *
37
+ * When passed to LLM providers (ChatGPT, Claude, Gemini, etc.), the LLM
38
+ * automatically selects functions and fills arguments from conversation.
39
+ * Execute the selected function via {@link ILlmController.execute}.
40
+ *
41
+ * Related functions:
42
+ *
43
+ * - {@link application} — Schemas only, without executor
44
+ * - {@link parameters} — Single parameters schema for structured output
45
+ * - {@link schema} — Single type schema
46
+ *
47
+ * @template Class Target class or interface type
48
+ * @template Config LLM schema configuration
49
+ * @param name Controller identifier name
50
+ * @param execute Executor instance
51
+ * @param config LLM application options
52
+ * @returns LLM function calling controller
53
+ */
54
+ export function controller<
55
+ Class extends Record<string, any>,
56
+ Config extends Partial<
57
+ ILlmSchema.IConfig & {
58
+ /**
59
+ * Whether to disallow superfluous properties or not.
60
+ *
61
+ * If configure as `true`, {@link validateEquals} function would be used
62
+ * for validation feedback, which is more strict than {@link validate}
63
+ * function.
64
+ *
65
+ * @default false
66
+ */
67
+ equals: boolean;
68
+ }
69
+ > = {},
70
+ >(
71
+ name: string,
72
+ execute: Class,
73
+ config?: Partial<Pick<ILlmApplication.IConfig<Class>, "validate">>,
74
+ ): ILlmController<Class>;
75
+
76
+ /** @internal */
77
+ export function controller(..._args: any[]): never {
78
+ NoTransformConfigurationError("llm.controller");
79
+ }
80
+
81
+ /**
82
+ * Creates LLM function calling application.
83
+ *
84
+ * @danger You must configure the generic argument `Class`
85
+ */
86
+ export function application(
87
+ config?: Partial<Pick<ILlmApplication.IConfig<any>, "validate">>,
88
+ ): never;
89
+
90
+ /**
91
+ * Creates LLM function calling application from class/interface.
92
+ *
93
+ * Generates {@link ILlmApplication} from a TypeScript class or interface,
94
+ * containing function calling schemas ({@link ILlmFunction}). Does not include
95
+ * an executor—use {@link controller} if you need execution capability.
96
+ *
97
+ * Each {@link ILlmFunction} includes a built-in {@link ILlmFunction.validate}
98
+ * function that validates LLM-generated arguments before execution. When
99
+ * validation fails, use `LlmJson.stringify()` from `@typia/utils` to format
100
+ * errors for LLM feedback, enabling auto-correction.
101
+ *
102
+ * When passed to LLM providers (ChatGPT, Claude, Gemini, etc.), the LLM
103
+ * automatically selects functions and fills arguments from conversation. You
104
+ * execute the function manually with the LLM-prepared arguments.
105
+ *
106
+ * Related functions:
107
+ *
108
+ * - {@link controller} — Includes executor alongside schemas
109
+ * - {@link parameters} — Single parameters schema for structured output
110
+ * - {@link schema} — Single type schema
111
+ *
112
+ * @template Class Target class or interface type
113
+ * @template Config LLM schema configuration
114
+ * @param config LLM application options
115
+ * @returns LLM function calling application
116
+ */
117
+ export function application<
118
+ Class extends Record<string, any>,
119
+ Config extends Partial<
120
+ ILlmSchema.IConfig & {
121
+ /**
122
+ * Whether to disallow superfluous properties or not.
123
+ *
124
+ * If configure as `true`, {@link validateEquals} function would be used
125
+ * for validation feedback, which is more strict than {@link validate}
126
+ * function.
127
+ *
128
+ * @default false
129
+ */
130
+ equals: boolean;
131
+ }
132
+ > = {},
133
+ >(
134
+ config?: Partial<Pick<ILlmApplication.IConfig<Class>, "validate">>,
135
+ ): ILlmApplication<Class>;
136
+
137
+ /** @internal */
138
+ export function application(): never {
139
+ NoTransformConfigurationError("llm.application");
140
+ }
141
+
142
+ /**
143
+ * Creates LLM structured output interface.
144
+ *
145
+ * @danger You must configure the generic argument `T`
146
+ */
147
+ export function structuredOutput(): never;
148
+
149
+ /**
150
+ * Creates LLM structured output interface from TypeScript object type.
151
+ *
152
+ * Generates {@link ILlmStructuredOutput} containing everything needed for
153
+ * handling LLM structured outputs: the JSON schema for prompting, and functions
154
+ * for parsing, coercing, and validating responses.
155
+ *
156
+ * Structured outputs allow LLMs to generate data conforming to a predefined
157
+ * schema instead of free-form text. This is useful for:
158
+ *
159
+ * - Extracting structured data from conversations
160
+ * - Generating typed responses for downstream processing
161
+ * - Ensuring consistent output formats across LLM calls
162
+ *
163
+ * Workflow:
164
+ *
165
+ * 1. Pass {@link ILlmStructuredOutput.parameters} schema to LLM provider
166
+ * 2. Receive LLM response (JSON string or pre-parsed object)
167
+ * 3. Use {@link ILlmStructuredOutput.parse} for raw strings or
168
+ * {@link ILlmStructuredOutput.coerce} for pre-parsed objects
169
+ * 4. Use {@link ILlmStructuredOutput.validate} to check the result
170
+ *
171
+ * Related functions:
172
+ *
173
+ * - {@link parameters} — Schema only, without parse/coerce/validate
174
+ * - {@link application} — Multiple function schemas from class/interface
175
+ * - {@link controller} — Application with executor
176
+ *
177
+ * @template T Target output type (object with static properties)
178
+ * @template Config LLM schema configuration
179
+ * @returns LLM structured output interface
180
+ */
181
+ export function structuredOutput<
182
+ T extends Record<string, any>,
183
+ Config extends Partial<
184
+ ILlmSchema.IConfig & {
185
+ /**
186
+ * Whether to disallow superfluous properties or not.
187
+ *
188
+ * If configure as `true`, {@link validateEquals} function would be used
189
+ * for validation feedback, which is more strict than {@link validate}
190
+ * function.
191
+ *
192
+ * @default false
193
+ */
194
+ equals: boolean;
195
+ }
196
+ > = {},
197
+ >(): ILlmStructuredOutput<T>;
198
+
199
+ /** @internal */
200
+ export function structuredOutput(): never {
201
+ NoTransformConfigurationError("llm.structuredOutput");
202
+ }
203
+
204
+ /* -----------------------------------------------------------
205
+ RAW SCHEMAS
206
+ ----------------------------------------------------------- */
207
+ /**
208
+ * Creates LLM parameters schema.
209
+ *
210
+ * @danger You must configure the generic argument `Parameters`
211
+ */
212
+ export function parameters(): never;
213
+
214
+ /**
215
+ * Creates LLM parameters schema from TypeScript object type.
216
+ *
217
+ * Generates {@link ILlmSchema.IParameters} for LLM function calling or
218
+ * structured outputs. LLMs use keyworded arguments only, so the type must be an
219
+ * object with static properties (no dynamic properties allowed).
220
+ *
221
+ * Use cases:
222
+ *
223
+ * - Function calling: LLM fills parameters from conversation
224
+ * - Structured outputs: LLM generates structured data, not plain text
225
+ *
226
+ * Related functions:
227
+ *
228
+ * - {@link application} — Multiple function schemas from class/interface
229
+ * - {@link controller} — Application with executor
230
+ * - {@link schema} — Single type schema (not parameters-specific)
231
+ *
232
+ * @template Parameters Target parameters type (object with static properties)
233
+ * @template Config LLM schema configuration
234
+ * @returns LLM parameters schema
235
+ */
236
+ export function parameters<
237
+ Parameters extends Record<string, any>,
238
+ Config extends Partial<ILlmSchema.IConfig> = {},
239
+ >(): ILlmSchema.IParameters;
240
+
241
+ /** @internal */
242
+ export function parameters(): never {
243
+ NoTransformConfigurationError("llm.parameters");
244
+ }
245
+
246
+ /**
247
+ * Creates LLM type schema.
248
+ *
249
+ * @danger You must configure the generic argument `T`
250
+ */
251
+ export function schema(): never;
252
+
253
+ /**
254
+ * Creates LLM type schema from TypeScript type.
255
+ *
256
+ * Generates {@link ILlmSchema} for use in LLM function calling. For actual
257
+ * function calling with TypeScript functions, use {@link application}. For
258
+ * structured output generation, use {@link parameters}.
259
+ *
260
+ * LLM function calling flow:
261
+ *
262
+ * 1. LLM selects function and fills arguments from conversation
263
+ * 2. You execute the function with LLM-prepared arguments
264
+ * 3. Return value is passed back to LLM via system prompt
265
+ * 4. LLM continues conversation based on return value
266
+ *
267
+ * Related functions:
268
+ *
269
+ * - {@link application} — Multiple function schemas from class/interface
270
+ * - {@link controller} — Application with executor
271
+ * - {@link parameters} — Parameters schema for structured output
272
+ *
273
+ * @template T Target type
274
+ * @template Config LLM schema configuration
275
+ * @param $defs Shared schema definitions for `$ref` referencing
276
+ * @returns LLM type schema
277
+ */
278
+ export function schema<T, Config extends Partial<ILlmSchema.IConfig> = {}>(
279
+ $defs: Record<string, ILlmSchema>,
280
+ ): ILlmSchema;
281
+
282
+ /** @internal */
283
+ export function schema(): never {
284
+ NoTransformConfigurationError("llm.schema");
285
+ }
286
+
287
+ /* -----------------------------------------------------------
288
+ UTILITY FUNCTIONS
289
+ ----------------------------------------------------------- */
290
+ /**
291
+ * Parse LLM response JSON with type coercion.
292
+ *
293
+ * @danger You must configure the generic argument `Parameters`
294
+ */
295
+ export function parse(input: string): never;
296
+
297
+ /**
298
+ * Parse lenient JSON with schema-based type coercion.
299
+ *
300
+ * Handles incomplete or malformed JSON commonly produced by LLMs:
301
+ *
302
+ * - Unclosed brackets, strings, trailing commas
303
+ * - JavaScript-style comments (`//` and multi-line)
304
+ * - Unquoted object keys, incomplete keywords (`tru`, `fal`, `nul`)
305
+ * - Markdown code block extraction, junk prefix skipping
306
+ *
307
+ * Also coerces double-stringified values based on the `Parameters` schema:
308
+ *
309
+ * - `"42"` → `42` (when schema expects number)
310
+ * - `"true"` → `true` (when schema expects boolean)
311
+ * - `"null"` → `null` (when schema expects null)
312
+ * - `"{...}"` → `{...}` (when schema expects object)
313
+ * - `"[...]"` → `[...]` (when schema expects array)
314
+ *
315
+ * Type validation is NOT performed—use {@link ILlmFunction.validate} or
316
+ * `typia.validate()` for that.
317
+ *
318
+ * For repeated parsing, use {@link createParse} to avoid regenerating the schema
319
+ * each time.
320
+ *
321
+ * Related functions:
322
+ *
323
+ * - {@link createParse} — Create reusable parser function
324
+ * - {@link coerce} — Type coercion for already-parsed objects
325
+ * - {@link parameters} — Generate parameters schema from type
326
+ *
327
+ * @template Parameters Target parameters type (object with static properties)
328
+ * @template Config LLM schema configuration
329
+ * @param input Raw JSON string (potentially incomplete or malformed)
330
+ * @returns Parse result with typed data on success, or partial data with errors
331
+ */
332
+ export function parse<
333
+ Parameters extends Record<string, any>,
334
+ Config extends Partial<ILlmSchema.IConfig> = {},
335
+ >(input: string): IJsonParseResult<Parameters>;
336
+
337
+ /** @internal */
338
+ export function parse(): never {
339
+ NoTransformConfigurationError("llm.parse");
340
+ }
341
+
342
+ /**
343
+ * Coerce LLM arguments to match expected schema types.
344
+ *
345
+ * LLMs often return values with incorrect types (e.g., numbers as strings).
346
+ * This function recursively coerces values based on the `Parameters` schema:
347
+ *
348
+ * - `"42"` → `42` (when schema expects number)
349
+ * - `"true"` → `true` (when schema expects boolean)
350
+ * - `"null"` → `null` (when schema expects null)
351
+ * - `"{...}"` → `{...}` (when schema expects object)
352
+ * - `"[...]"` → `[...]` (when schema expects array)
353
+ *
354
+ * Use this when your SDK provides already-parsed objects but values may have
355
+ * wrong types. For raw JSON strings, use {@link parse} instead.
356
+ *
357
+ * For repeated coercion, use {@link createCoerce} to avoid regenerating the
358
+ * schema each time.
359
+ *
360
+ * Type validation is NOT performed—use {@link ILlmFunction.validate} or
361
+ * `typia.validate()` for that.
362
+ *
363
+ * Related functions:
364
+ *
365
+ * - {@link createCoerce} — Create reusable coercer function
366
+ * - {@link parse} — Parse and coerce raw JSON strings
367
+ * - {@link parameters} — Generate parameters schema from type
368
+ *
369
+ * @template Parameters Target parameters type (object with static properties)
370
+ * @template Config LLM schema configuration
371
+ * @param input Parsed arguments object from LLM (with potentially wrong types)
372
+ * @returns Coerced arguments with corrected types
373
+ */
374
+ export function coerce<
375
+ Parameters extends Record<string, any>,
376
+ Config extends Partial<ILlmSchema.IConfig> = {},
377
+ >(input: Parameters): Parameters;
378
+
379
+ /** @internal */
380
+ export function coerce(): never {
381
+ NoTransformConfigurationError("llm.coerce");
382
+ }
383
+
384
+ /**
385
+ * Create reusable LLM JSON parser with type coercion.
386
+ *
387
+ * @danger You must configure the generic argument `Parameters`
388
+ */
389
+ export function createParse(): never;
390
+
391
+ /**
392
+ * Create reusable lenient JSON parser with schema-based type coercion.
393
+ *
394
+ * Returns a parser function that handles incomplete or malformed JSON commonly
395
+ * produced by LLMs:
396
+ *
397
+ * - Unclosed brackets, strings, trailing commas
398
+ * - JavaScript-style comments (`//` and multi-line)
399
+ * - Unquoted object keys, incomplete keywords (`tru`, `fal`, `nul`)
400
+ * - Markdown code block extraction, junk prefix skipping
401
+ *
402
+ * Also coerces double-stringified values based on the `Parameters` schema:
403
+ *
404
+ * - `"42"` → `42` (when schema expects number)
405
+ * - `"true"` → `true` (when schema expects boolean)
406
+ * - `"null"` → `null` (when schema expects null)
407
+ * - `"{...}"` → `{...}` (when schema expects object)
408
+ * - `"[...]"` → `[...]` (when schema expects array)
409
+ *
410
+ * Use this instead of {@link parse} when parsing multiple inputs to avoid
411
+ * regenerating the schema each time.
412
+ *
413
+ * Type validation is NOT performed—use {@link ILlmFunction.validate} or
414
+ * `typia.validate()` for that.
415
+ *
416
+ * Related functions:
417
+ *
418
+ * - {@link parse} — One-shot parsing (regenerates schema each call)
419
+ * - {@link createCoerce} — Create reusable coercer function
420
+ * - {@link parameters} — Generate parameters schema from type
421
+ *
422
+ * @template Parameters Target parameters type (object with static properties)
423
+ * @template Config LLM schema configuration
424
+ * @returns Reusable parser function
425
+ */
426
+ export function createParse<
427
+ Parameters extends Record<string, any>,
428
+ Config extends Partial<ILlmSchema.IConfig> = {},
429
+ >(): (input: string) => IJsonParseResult<Parameters>;
430
+
431
+ /** @internal */
432
+ export function createParse(): never {
433
+ NoTransformConfigurationError("llm.createParse");
434
+ }
435
+
436
+ /**
437
+ * Create reusable LLM arguments coercer.
438
+ *
439
+ * @danger You must configure the generic argument `Parameters`
440
+ */
441
+ export function createCoerce(): never;
442
+
443
+ /**
444
+ * Create reusable coercer for LLM arguments.
445
+ *
446
+ * Returns a coercer function that fixes incorrect types commonly returned by
447
+ * LLMs (e.g., numbers as strings). Coerces values based on the `Parameters`
448
+ * schema:
449
+ *
450
+ * - `"42"` → `42` (when schema expects number)
451
+ * - `"true"` → `true` (when schema expects boolean)
452
+ * - `"null"` → `null` (when schema expects null)
453
+ * - `"{...}"` → `{...}` (when schema expects object)
454
+ * - `"[...]"` → `[...]` (when schema expects array)
455
+ *
456
+ * Use this instead of {@link coerce} when coercing multiple inputs to avoid
457
+ * regenerating the schema each time.
458
+ *
459
+ * Type validation is NOT performed—use {@link ILlmFunction.validate} or
460
+ * `typia.validate()` for that.
461
+ *
462
+ * Related functions:
463
+ *
464
+ * - {@link coerce} — One-shot coercion (regenerates schema each call)
465
+ * - {@link createParse} — Create reusable parser function
466
+ * - {@link parameters} — Generate parameters schema from type
467
+ *
468
+ * @template Parameters Target parameters type (object with static properties)
469
+ * @template Config LLM schema configuration
470
+ * @returns Reusable coercer function
471
+ */
472
+ export function createCoerce<
473
+ Parameters extends Record<string, any>,
474
+ Config extends Partial<ILlmSchema.IConfig> = {},
475
+ >(): (input: Parameters) => Parameters;
476
+
477
+ /** @internal */
478
+ export function createCoerce(): never {
479
+ NoTransformConfigurationError("llm.createCoerce");
480
+ }