@typia/interface 12.0.0-dev.20260315 → 12.0.0
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/LICENSE +21 -21
- package/README.md +29 -29
- package/package.json +1 -1
- package/src/http/IHttpLlmApplication.ts +72 -72
- package/src/http/IHttpLlmFunction.ts +34 -34
- package/src/http/IHttpMigrateApplication.ts +48 -48
- package/src/http/IHttpMigrateRoute.ts +165 -165
- package/src/openapi/OpenApi.ts +680 -680
- package/src/openapi/OpenApiV3.ts +663 -663
- package/src/openapi/OpenApiV3_1.ts +743 -743
- package/src/openapi/OpenApiV3_2.ts +773 -773
- package/src/openapi/SwaggerV2.ts +567 -567
- package/src/openapi/index.ts +5 -5
- package/src/schema/IJsonParseResult.ts +134 -134
- package/src/schema/ILlmApplication.ts +98 -98
- package/src/schema/ILlmSchema.ts +473 -473
- package/src/schema/ILlmStructuredOutput.ts +112 -112
- package/src/schema/index.ts +15 -15
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
import { IJsonParseResult } from "./IJsonParseResult";
|
|
2
|
-
import { ILlmSchema } from "./ILlmSchema";
|
|
3
|
-
import { IValidation } from "./IValidation";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* LLM structured output schema with parsing and validation utilities.
|
|
7
|
-
*
|
|
8
|
-
* `ILlmStructuredOutput<T>` is generated by `typia.llm.structuredOutput<T>()`
|
|
9
|
-
* to provide everything needed for handling LLM structured outputs: the JSON
|
|
10
|
-
* schema for prompting, and functions for parsing, coercing, and validating
|
|
11
|
-
* responses.
|
|
12
|
-
*
|
|
13
|
-
* Structured outputs allow LLMs to generate data conforming to a predefined
|
|
14
|
-
* schema instead of free-form text. This is useful for:
|
|
15
|
-
*
|
|
16
|
-
* - Extracting structured data from conversations
|
|
17
|
-
* - Generating typed responses for downstream processing
|
|
18
|
-
* - Ensuring consistent output formats across LLM calls
|
|
19
|
-
*
|
|
20
|
-
* Workflow:
|
|
21
|
-
*
|
|
22
|
-
* 1. Pass {@link parameters} schema to LLM provider
|
|
23
|
-
* 2. Receive LLM response (JSON string or pre-parsed object)
|
|
24
|
-
* 3. Use {@link parse} for raw strings or {@link coerce} for pre-parsed objects
|
|
25
|
-
* 4. Use {@link validate} to check the result and get detailed errors
|
|
26
|
-
*
|
|
27
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
28
|
-
* @template T The expected output type
|
|
29
|
-
*/
|
|
30
|
-
export interface ILlmStructuredOutput<T = unknown> {
|
|
31
|
-
/**
|
|
32
|
-
* JSON schema for the structured output.
|
|
33
|
-
*
|
|
34
|
-
* Pass this schema to LLM providers (OpenAI, Anthropic, Google, etc.) to
|
|
35
|
-
* constrain the output format. The schema includes `$defs` for shared type
|
|
36
|
-
* definitions and `properties` for the output structure.
|
|
37
|
-
*
|
|
38
|
-
* Most LLM providers accept this directly in their structured output or
|
|
39
|
-
* response format configuration.
|
|
40
|
-
*/
|
|
41
|
-
parameters: ILlmSchema.IParameters;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Lenient JSON parser with schema-based type coercion.
|
|
45
|
-
*
|
|
46
|
-
* Handles incomplete or malformed JSON commonly produced by LLMs:
|
|
47
|
-
*
|
|
48
|
-
* - Unclosed brackets, strings, trailing commas
|
|
49
|
-
* - JavaScript-style comments (`//` and multi-line)
|
|
50
|
-
* - Unquoted object keys, incomplete keywords (`tru`, `fal`, `nul`)
|
|
51
|
-
* - Markdown code block extraction, junk prefix skipping
|
|
52
|
-
*
|
|
53
|
-
* Also coerces double-stringified values based on the schema:
|
|
54
|
-
*
|
|
55
|
-
* - `"42"` → `42` (when schema expects number)
|
|
56
|
-
* - `"true"` → `true` (when schema expects boolean)
|
|
57
|
-
* - `"null"` → `null` (when schema expects null)
|
|
58
|
-
* - `"{...}"` → `{...}` (when schema expects object)
|
|
59
|
-
* - `"[...]"` → `[...]` (when schema expects array)
|
|
60
|
-
*
|
|
61
|
-
* Type validation is NOT performed — use {@link validate} after parsing.
|
|
62
|
-
*
|
|
63
|
-
* If the SDK (e.g., LangChain, Vercel AI, MCP) already parses JSON internally
|
|
64
|
-
* and provides a pre-parsed object, use {@link coerce} instead.
|
|
65
|
-
*
|
|
66
|
-
* @param input Raw JSON string from LLM output
|
|
67
|
-
* @returns Parse result with data on success, or partial data with errors
|
|
68
|
-
*/
|
|
69
|
-
parse: (input: string) => IJsonParseResult<T>;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Coerce pre-parsed output to match expected schema types.
|
|
73
|
-
*
|
|
74
|
-
* **Use this only when the SDK already parses JSON internally.** For raw JSON
|
|
75
|
-
* strings from LLM output, use {@link parse} instead — it handles both lenient
|
|
76
|
-
* parsing and type coercion in one step.
|
|
77
|
-
*
|
|
78
|
-
* LLMs often return values with incorrect types even after parsing:
|
|
79
|
-
*
|
|
80
|
-
* - `"42"` → `42` (when schema expects number)
|
|
81
|
-
* - `"true"` → `true` (when schema expects boolean)
|
|
82
|
-
* - `"null"` → `null` (when schema expects null)
|
|
83
|
-
* - `"{...}"` → `{...}` (when schema expects object)
|
|
84
|
-
* - `"[...]"` → `[...]` (when schema expects array)
|
|
85
|
-
*
|
|
86
|
-
* This function recursively coerces these double-stringified values based on
|
|
87
|
-
* the {@link parameters} schema.
|
|
88
|
-
*
|
|
89
|
-
* Type validation is NOT performed — use {@link validate} after coercion.
|
|
90
|
-
*
|
|
91
|
-
* @param input Pre-parsed output object from SDK
|
|
92
|
-
* @returns Coerced output with corrected types
|
|
93
|
-
*/
|
|
94
|
-
coerce: (input: unknown) => T;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Validates LLM-generated output against the schema.
|
|
98
|
-
*
|
|
99
|
-
* LLMs frequently make type errors such as returning strings instead of
|
|
100
|
-
* numbers or missing required properties. Use this validator to check output
|
|
101
|
-
* before further processing.
|
|
102
|
-
*
|
|
103
|
-
* When validation fails, use {@link LlmJson.stringify} from `@typia/utils` to
|
|
104
|
-
* format the error for LLM feedback. The formatted output shows the invalid
|
|
105
|
-
* JSON with inline error comments, helping the LLM understand and correct its
|
|
106
|
-
* mistakes in the next turn.
|
|
107
|
-
*
|
|
108
|
-
* @param input The output generated by the LLM
|
|
109
|
-
* @returns Validation result with success status and any errors
|
|
110
|
-
*/
|
|
111
|
-
validate: (input: unknown) => IValidation<T>;
|
|
112
|
-
}
|
|
1
|
+
import { IJsonParseResult } from "./IJsonParseResult";
|
|
2
|
+
import { ILlmSchema } from "./ILlmSchema";
|
|
3
|
+
import { IValidation } from "./IValidation";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* LLM structured output schema with parsing and validation utilities.
|
|
7
|
+
*
|
|
8
|
+
* `ILlmStructuredOutput<T>` is generated by `typia.llm.structuredOutput<T>()`
|
|
9
|
+
* to provide everything needed for handling LLM structured outputs: the JSON
|
|
10
|
+
* schema for prompting, and functions for parsing, coercing, and validating
|
|
11
|
+
* responses.
|
|
12
|
+
*
|
|
13
|
+
* Structured outputs allow LLMs to generate data conforming to a predefined
|
|
14
|
+
* schema instead of free-form text. This is useful for:
|
|
15
|
+
*
|
|
16
|
+
* - Extracting structured data from conversations
|
|
17
|
+
* - Generating typed responses for downstream processing
|
|
18
|
+
* - Ensuring consistent output formats across LLM calls
|
|
19
|
+
*
|
|
20
|
+
* Workflow:
|
|
21
|
+
*
|
|
22
|
+
* 1. Pass {@link parameters} schema to LLM provider
|
|
23
|
+
* 2. Receive LLM response (JSON string or pre-parsed object)
|
|
24
|
+
* 3. Use {@link parse} for raw strings or {@link coerce} for pre-parsed objects
|
|
25
|
+
* 4. Use {@link validate} to check the result and get detailed errors
|
|
26
|
+
*
|
|
27
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
28
|
+
* @template T The expected output type
|
|
29
|
+
*/
|
|
30
|
+
export interface ILlmStructuredOutput<T = unknown> {
|
|
31
|
+
/**
|
|
32
|
+
* JSON schema for the structured output.
|
|
33
|
+
*
|
|
34
|
+
* Pass this schema to LLM providers (OpenAI, Anthropic, Google, etc.) to
|
|
35
|
+
* constrain the output format. The schema includes `$defs` for shared type
|
|
36
|
+
* definitions and `properties` for the output structure.
|
|
37
|
+
*
|
|
38
|
+
* Most LLM providers accept this directly in their structured output or
|
|
39
|
+
* response format configuration.
|
|
40
|
+
*/
|
|
41
|
+
parameters: ILlmSchema.IParameters;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Lenient JSON parser with schema-based type coercion.
|
|
45
|
+
*
|
|
46
|
+
* Handles incomplete or malformed JSON commonly produced by LLMs:
|
|
47
|
+
*
|
|
48
|
+
* - Unclosed brackets, strings, trailing commas
|
|
49
|
+
* - JavaScript-style comments (`//` and multi-line)
|
|
50
|
+
* - Unquoted object keys, incomplete keywords (`tru`, `fal`, `nul`)
|
|
51
|
+
* - Markdown code block extraction, junk prefix skipping
|
|
52
|
+
*
|
|
53
|
+
* Also coerces double-stringified values based on the schema:
|
|
54
|
+
*
|
|
55
|
+
* - `"42"` → `42` (when schema expects number)
|
|
56
|
+
* - `"true"` → `true` (when schema expects boolean)
|
|
57
|
+
* - `"null"` → `null` (when schema expects null)
|
|
58
|
+
* - `"{...}"` → `{...}` (when schema expects object)
|
|
59
|
+
* - `"[...]"` → `[...]` (when schema expects array)
|
|
60
|
+
*
|
|
61
|
+
* Type validation is NOT performed — use {@link validate} after parsing.
|
|
62
|
+
*
|
|
63
|
+
* If the SDK (e.g., LangChain, Vercel AI, MCP) already parses JSON internally
|
|
64
|
+
* and provides a pre-parsed object, use {@link coerce} instead.
|
|
65
|
+
*
|
|
66
|
+
* @param input Raw JSON string from LLM output
|
|
67
|
+
* @returns Parse result with data on success, or partial data with errors
|
|
68
|
+
*/
|
|
69
|
+
parse: (input: string) => IJsonParseResult<T>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Coerce pre-parsed output to match expected schema types.
|
|
73
|
+
*
|
|
74
|
+
* **Use this only when the SDK already parses JSON internally.** For raw JSON
|
|
75
|
+
* strings from LLM output, use {@link parse} instead — it handles both lenient
|
|
76
|
+
* parsing and type coercion in one step.
|
|
77
|
+
*
|
|
78
|
+
* LLMs often return values with incorrect types even after parsing:
|
|
79
|
+
*
|
|
80
|
+
* - `"42"` → `42` (when schema expects number)
|
|
81
|
+
* - `"true"` → `true` (when schema expects boolean)
|
|
82
|
+
* - `"null"` → `null` (when schema expects null)
|
|
83
|
+
* - `"{...}"` → `{...}` (when schema expects object)
|
|
84
|
+
* - `"[...]"` → `[...]` (when schema expects array)
|
|
85
|
+
*
|
|
86
|
+
* This function recursively coerces these double-stringified values based on
|
|
87
|
+
* the {@link parameters} schema.
|
|
88
|
+
*
|
|
89
|
+
* Type validation is NOT performed — use {@link validate} after coercion.
|
|
90
|
+
*
|
|
91
|
+
* @param input Pre-parsed output object from SDK
|
|
92
|
+
* @returns Coerced output with corrected types
|
|
93
|
+
*/
|
|
94
|
+
coerce: (input: unknown) => T;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Validates LLM-generated output against the schema.
|
|
98
|
+
*
|
|
99
|
+
* LLMs frequently make type errors such as returning strings instead of
|
|
100
|
+
* numbers or missing required properties. Use this validator to check output
|
|
101
|
+
* before further processing.
|
|
102
|
+
*
|
|
103
|
+
* When validation fails, use {@link LlmJson.stringify} from `@typia/utils` to
|
|
104
|
+
* format the error for LLM feedback. The formatted output shows the invalid
|
|
105
|
+
* JSON with inline error comments, helping the LLM understand and correct its
|
|
106
|
+
* mistakes in the next turn.
|
|
107
|
+
*
|
|
108
|
+
* @param input The output generated by the LLM
|
|
109
|
+
* @returns Validation result with success status and any errors
|
|
110
|
+
*/
|
|
111
|
+
validate: (input: unknown) => IValidation<T>;
|
|
112
|
+
}
|
package/src/schema/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export * from "./IResult";
|
|
2
|
-
export * from "./IValidation";
|
|
3
|
-
|
|
4
|
-
export * from "./IJsonSchemaTransformError";
|
|
5
|
-
export * from "./IJsonSchemaApplication";
|
|
6
|
-
export * from "./IJsonSchemaCollection";
|
|
7
|
-
export * from "./IJsonSchemaUnit";
|
|
8
|
-
export * from "./IJsonSchemaAttribute";
|
|
9
|
-
|
|
10
|
-
export * from "./ILlmController";
|
|
11
|
-
export * from "./ILlmApplication";
|
|
12
|
-
export * from "./ILlmFunction";
|
|
13
|
-
export * from "./ILlmSchema";
|
|
14
|
-
export * from "./ILlmStructuredOutput";
|
|
15
|
-
export * from "./IJsonParseResult";
|
|
1
|
+
export * from "./IResult";
|
|
2
|
+
export * from "./IValidation";
|
|
3
|
+
|
|
4
|
+
export * from "./IJsonSchemaTransformError";
|
|
5
|
+
export * from "./IJsonSchemaApplication";
|
|
6
|
+
export * from "./IJsonSchemaCollection";
|
|
7
|
+
export * from "./IJsonSchemaUnit";
|
|
8
|
+
export * from "./IJsonSchemaAttribute";
|
|
9
|
+
|
|
10
|
+
export * from "./ILlmController";
|
|
11
|
+
export * from "./ILlmApplication";
|
|
12
|
+
export * from "./ILlmFunction";
|
|
13
|
+
export * from "./ILlmSchema";
|
|
14
|
+
export * from "./ILlmStructuredOutput";
|
|
15
|
+
export * from "./IJsonParseResult";
|