Skip to content

Commit ff529d7

Browse files
author
awstools
committed
feat(client-bedrock-runtime): Added support for structured outputs to Converse and ConverseStream APIs.
1 parent f92e1d6 commit ff529d7

9 files changed

Lines changed: 312 additions & 6 deletions

File tree

clients/client-bedrock-runtime/src/commands/ConverseCommand.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ export interface ConverseCommandOutput extends ConverseResponse, __MetadataBeare
297297
* inputSchema: { // ToolInputSchema Union: only one key present
298298
* json: "DOCUMENT_VALUE",
299299
* },
300+
* strict: true || false,
300301
* },
301302
* systemTool: { // SystemTool
302303
* name: "STRING_VALUE", // required
@@ -335,6 +336,18 @@ export interface ConverseCommandOutput extends ConverseResponse, __MetadataBeare
335336
* serviceTier: { // ServiceTier
336337
* type: "priority" || "default" || "flex" || "reserved", // required
337338
* },
339+
* outputConfig: { // OutputConfig
340+
* textFormat: { // OutputFormat
341+
* type: "json_schema", // required
342+
* structure: { // OutputFormatStructure Union: only one key present
343+
* jsonSchema: { // JsonSchemaDefinition
344+
* schema: "STRING_VALUE", // required
345+
* name: "STRING_VALUE",
346+
* description: "STRING_VALUE",
347+
* },
348+
* },
349+
* },
350+
* },
338351
* };
339352
* const command = new ConverseCommand(input);
340353
* const response = await client.send(command);

clients/client-bedrock-runtime/src/commands/ConverseStreamCommand.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ export interface ConverseStreamCommandOutput extends ConverseStreamResponse, __M
297297
* inputSchema: { // ToolInputSchema Union: only one key present
298298
* json: "DOCUMENT_VALUE",
299299
* },
300+
* strict: true || false,
300301
* },
301302
* systemTool: { // SystemTool
302303
* name: "STRING_VALUE", // required
@@ -336,6 +337,18 @@ export interface ConverseStreamCommandOutput extends ConverseStreamResponse, __M
336337
* serviceTier: { // ServiceTier
337338
* type: "priority" || "default" || "flex" || "reserved", // required
338339
* },
340+
* outputConfig: { // OutputConfig
341+
* textFormat: { // OutputFormat
342+
* type: "json_schema", // required
343+
* structure: { // OutputFormatStructure Union: only one key present
344+
* jsonSchema: { // JsonSchemaDefinition
345+
* schema: "STRING_VALUE", // required
346+
* name: "STRING_VALUE",
347+
* description: "STRING_VALUE",
348+
* },
349+
* },
350+
* },
351+
* },
339352
* };
340353
* const command = new ConverseStreamCommand(input);
341354
* const response = await client.send(command);

clients/client-bedrock-runtime/src/commands/CountTokensCommand.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ export interface CountTokensCommandOutput extends CountTokensResponse, __Metadat
294294
* inputSchema: { // ToolInputSchema Union: only one key present
295295
* json: "DOCUMENT_VALUE",
296296
* },
297+
* strict: true || false,
297298
* },
298299
* systemTool: { // SystemTool
299300
* name: "STRING_VALUE", // required

clients/client-bedrock-runtime/src/models/enums.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,18 @@ export const ConversationRole = {
530530
*/
531531
export type ConversationRole = (typeof ConversationRole)[keyof typeof ConversationRole];
532532

533+
/**
534+
* @public
535+
* @enum
536+
*/
537+
export const OutputFormatType = {
538+
JSON_SCHEMA: "json_schema",
539+
} as const;
540+
/**
541+
* @public
542+
*/
543+
export type OutputFormatType = (typeof OutputFormatType)[keyof typeof OutputFormatType];
544+
533545
/**
534546
* @public
535547
* @enum

clients/client-bedrock-runtime/src/models/models_0.ts

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
GuardrailTrace,
3434
GuardrailWordPolicyAction,
3535
ImageFormat,
36+
OutputFormatType,
3637
PerformanceConfigLatency,
3738
ServiceTierType,
3839
SortAsyncInvocationBy,
@@ -3145,6 +3146,99 @@ export interface Message {
31453146
content: ContentBlock[] | undefined;
31463147
}
31473148

3149+
/**
3150+
* <p> JSON schema structured output format options. </p>
3151+
* @public
3152+
*/
3153+
export interface JsonSchemaDefinition {
3154+
/**
3155+
* <p> The JSON schema to constrain the model's output. For more information, see <a href="https://json-schema.org/understanding-json-schema/reference">JSON Schema Reference</a>. </p>
3156+
* @public
3157+
*/
3158+
schema: string | undefined;
3159+
3160+
/**
3161+
* <p> The name of the JSON schema. </p>
3162+
* @public
3163+
*/
3164+
name?: string | undefined;
3165+
3166+
/**
3167+
* <p> A description of the JSON schema. </p>
3168+
* @public
3169+
*/
3170+
description?: string | undefined;
3171+
}
3172+
3173+
/**
3174+
* <p> The structure that the model's output must adhere to. </p>
3175+
* @public
3176+
*/
3177+
export type OutputFormatStructure =
3178+
| OutputFormatStructure.JsonSchemaMember
3179+
| OutputFormatStructure.$UnknownMember;
3180+
3181+
/**
3182+
* @public
3183+
*/
3184+
export namespace OutputFormatStructure {
3185+
/**
3186+
* <p> A JSON schema structure that the model's output must adhere to. </p>
3187+
* @public
3188+
*/
3189+
export interface JsonSchemaMember {
3190+
jsonSchema: JsonSchemaDefinition;
3191+
$unknown?: never;
3192+
}
3193+
3194+
/**
3195+
* @public
3196+
*/
3197+
export interface $UnknownMember {
3198+
jsonSchema?: never;
3199+
$unknown: [string, any];
3200+
}
3201+
3202+
/**
3203+
* @deprecated unused in schema-serde mode.
3204+
*
3205+
*/
3206+
export interface Visitor<T> {
3207+
jsonSchema: (value: JsonSchemaDefinition) => T;
3208+
_: (name: string, value: any) => T;
3209+
}
3210+
}
3211+
3212+
/**
3213+
* <p> Structured output parameters to control the model's response. </p>
3214+
* @public
3215+
*/
3216+
export interface OutputFormat {
3217+
/**
3218+
* <p> The type of structured output format. </p>
3219+
* @public
3220+
*/
3221+
type: OutputFormatType | undefined;
3222+
3223+
/**
3224+
* <p> The structure that the model's output must adhere to. </p>
3225+
* @public
3226+
*/
3227+
structure: OutputFormatStructure | undefined;
3228+
}
3229+
3230+
/**
3231+
* <p>Output configuration for a model response in a call to <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html">Converse</a> or <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html">ConverseStream</a>.</p>
3232+
* @public
3233+
*/
3234+
export interface OutputConfig {
3235+
/**
3236+
* <p>Structured output parameters to control the model's text response. </p>
3237+
* @public
3238+
*/
3239+
textFormat?: OutputFormat | undefined;
3240+
}
3241+
31483242
/**
31493243
* <p>Performance settings for a model.</p>
31503244
* @public
@@ -3443,6 +3537,12 @@ export interface ToolSpecification {
34433537
* @public
34443538
*/
34453539
inputSchema: ToolInputSchema | undefined;
3540+
3541+
/**
3542+
* <p>Flag to enable structured output enforcement on a tool usage response.</p>
3543+
* @public
3544+
*/
3545+
strict?: boolean | undefined;
34463546
}
34473547

34483548
/**
@@ -3607,6 +3707,12 @@ export interface ConverseRequest {
36073707
* @public
36083708
*/
36093709
serviceTier?: ServiceTier | undefined;
3710+
3711+
/**
3712+
* <p>Output configuration for a model response.</p>
3713+
* @public
3714+
*/
3715+
outputConfig?: OutputConfig | undefined;
36103716
}
36113717

36123718
/**
@@ -3938,6 +4044,12 @@ export interface ConverseStreamRequest {
39384044
* @public
39394045
*/
39404046
serviceTier?: ServiceTier | undefined;
4047+
4048+
/**
4049+
* <p>Output configuration for a model response.</p>
4050+
* @public
4051+
*/
4052+
outputConfig?: OutputConfig | undefined;
39414053
}
39424054

39434055
/**

clients/client-bedrock-runtime/src/schemas/schemas_0.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ const _IMWRSR = "InvokeModelWithResponseStreamRequest";
154154
const _IMWRSRn = "InvokeModelWithResponseStreamResponse";
155155
const _IS = "ImageSource";
156156
const _ISE = "InternalServerException";
157+
const _JSD = "JsonSchemaDefinition";
157158
const _LAI = "ListAsyncInvokes";
158159
const _LAIR = "ListAsyncInvokesRequest";
159160
const _LAIRi = "ListAsyncInvokesResponse";
@@ -166,6 +167,9 @@ const _MSEE = "ModelStreamErrorException";
166167
const _MSEe = "MessageStopEvent";
167168
const _MTE = "ModelTimeoutException";
168169
const _Me = "Messages";
170+
const _OC = "OutputConfig";
171+
const _OF = "OutputFormat";
172+
const _OFS = "OutputFormatStructure";
169173
const _PB = "PartBody";
170174
const _PC = "PerformanceConfiguration";
171175
const _PP = "PayloadPart";
@@ -321,6 +325,7 @@ const _ima = "image";
321325
const _imp = "impossible";
322326
const _in = "invalid";
323327
const _j = "json";
328+
const _jS = "jsonSchema";
324329
const _k = "key";
325330
const _kKI = "kmsKeyId";
326331
const _l = "location";
@@ -351,6 +356,7 @@ const _nT = "nextToken";
351356
const _nTo = "noTranslations";
352357
const _o = "outputs";
353358
const _oA = "outputAssessments";
359+
const _oC = "outputConfig";
354360
const _oDC = "outputDataConfig";
355361
const _oM = "originalMessage";
356362
const _oS = "outputScope";
@@ -400,6 +406,7 @@ const _sU = "s3Uri";
400406
const _sUE = "serviceUnavailableException";
401407
const _sa = "satisfiable";
402408
const _sc = "score";
409+
const _sch = "schema";
403410
const _se = "server";
404411
const _si = "signature";
405412
const _sm = "smithy.ts.sdk.synthetic.com.amazonaws.bedrockruntime";
@@ -408,6 +415,8 @@ const _sta = "start";
408415
const _stat = "statements";
409416
const _str = "stream";
410417
const _stre = "streaming";
418+
const _stri = "strict";
419+
const _stru = "structure";
411420
const _sy = "system";
412421
const _t = "ttl";
413422
const _tA = "translationAmbiguous";
@@ -416,6 +425,7 @@ const _tCe = "textCharacters";
416425
const _tCo = "toolChoice";
417426
const _tCoo = "tooComplex";
418427
const _tE = "throttlingException";
428+
const _tF = "textFormat";
419429
const _tP = "topicPolicy";
420430
const _tPU = "topicPolicyUnits";
421431
const _tPo = "topP";
@@ -605,8 +615,8 @@ export var ConverseMetrics$: StaticStructureSchema = [3, n0, _CM,
605615
];
606616
export var ConverseRequest$: StaticStructureSchema = [3, n0, _CR,
607617
0,
608-
[_mI, _me, _sy, _iC, _tC, _gCu, _aMRF, _pV, _aMRFP, _rM, _pC, _sTe],
609-
[[0, 1], [() => Messages, 0], [() => SystemContentBlocks, 0], () => InferenceConfiguration$, () => ToolConfiguration$, () => GuardrailConfiguration$, 15, [() => PromptVariableMap, 0], 64 | 0, [() => RequestMetadata, 0], () => PerformanceConfiguration$, () => ServiceTier$], 1
618+
[_mI, _me, _sy, _iC, _tC, _gCu, _aMRF, _pV, _aMRFP, _rM, _pC, _sTe, _oC],
619+
[[0, 1], [() => Messages, 0], [() => SystemContentBlocks, 0], () => InferenceConfiguration$, () => ToolConfiguration$, () => GuardrailConfiguration$, 15, [() => PromptVariableMap, 0], 64 | 0, [() => RequestMetadata, 0], () => PerformanceConfiguration$, () => ServiceTier$, [() => OutputConfig$, 0]], 1
610620
];
611621
export var ConverseResponse$: StaticStructureSchema = [3, n0, _CRo,
612622
0,
@@ -625,8 +635,8 @@ export var ConverseStreamMetrics$: StaticStructureSchema = [3, n0, _CSM,
625635
];
626636
export var ConverseStreamRequest$: StaticStructureSchema = [3, n0, _CSR,
627637
0,
628-
[_mI, _me, _sy, _iC, _tC, _gCu, _aMRF, _pV, _aMRFP, _rM, _pC, _sTe],
629-
[[0, 1], [() => Messages, 0], [() => SystemContentBlocks, 0], () => InferenceConfiguration$, () => ToolConfiguration$, () => GuardrailStreamConfiguration$, 15, [() => PromptVariableMap, 0], 64 | 0, [() => RequestMetadata, 0], () => PerformanceConfiguration$, () => ServiceTier$], 1
638+
[_mI, _me, _sy, _iC, _tC, _gCu, _aMRF, _pV, _aMRFP, _rM, _pC, _sTe, _oC],
639+
[[0, 1], [() => Messages, 0], [() => SystemContentBlocks, 0], () => InferenceConfiguration$, () => ToolConfiguration$, () => GuardrailStreamConfiguration$, 15, [() => PromptVariableMap, 0], 64 | 0, [() => RequestMetadata, 0], () => PerformanceConfiguration$, () => ServiceTier$, [() => OutputConfig$, 0]], 1
630640
];
631641
export var ConverseStreamResponse$: StaticStructureSchema = [3, n0, _CSRo,
632642
0,
@@ -959,6 +969,11 @@ export var InvokeModelWithResponseStreamResponse$: StaticStructureSchema = [3, n
959969
[_bo, _cT, _pCL, _sTe],
960970
[[() => ResponseStream$, 16], [0, { [_hH]: _XABCT }], [0, { [_hH]: _XABPL }], [0, { [_hH]: _XABST }]], 2
961971
];
972+
export var JsonSchemaDefinition$: StaticStructureSchema = [3, n0, _JSD,
973+
0,
974+
[_sch, _n, _des],
975+
[0, 0, 0], 1
976+
];
962977
export var ListAsyncInvokesRequest$: StaticStructureSchema = [3, n0, _LAIR,
963978
0,
964979
[_sTA, _sTB, _sE, _mR, _nT, _sB, _sO],
@@ -1008,6 +1023,16 @@ export var ModelTimeoutException$: StaticErrorSchema = [-3, n0, _MTE,
10081023
[0]
10091024
];
10101025
TypeRegistry.for(n0).registerError(ModelTimeoutException$, ModelTimeoutException);
1026+
export var OutputConfig$: StaticStructureSchema = [3, n0, _OC,
1027+
0,
1028+
[_tF],
1029+
[[() => OutputFormat$, 0]]
1030+
];
1031+
export var OutputFormat$: StaticStructureSchema = [3, n0, _OF,
1032+
0,
1033+
[_ty, _stru],
1034+
[0, [() => OutputFormatStructure$, 0]], 2
1035+
];
10111036
export var PayloadPart$: StaticStructureSchema = [3, n0, _PP,
10121037
8,
10131038
[_b],
@@ -1124,8 +1149,8 @@ export var ToolResultBlockStart$: StaticStructureSchema = [3, n0, _TRBS,
11241149
];
11251150
export var ToolSpecification$: StaticStructureSchema = [3, n0, _TS,
11261151
0,
1127-
[_n, _iS, _des],
1128-
[0, () => ToolInputSchema$, 0], 2
1152+
[_n, _iS, _des, _stri],
1153+
[0, () => ToolInputSchema$, 0, 2], 2
11291154
];
11301155
export var ToolUseBlock$: StaticStructureSchema = [3, n0, _TUB,
11311156
0,
@@ -1398,6 +1423,11 @@ export var InvokeModelWithBidirectionalStreamOutput$: StaticUnionSchema = [4, n0
13981423
[_ch, _iSE, _mSEE, _vE, _tE, _mTE, _sUE],
13991424
[[() => BidirectionalOutputPayloadPart$, 0], [() => InternalServerException$, 0], [() => ModelStreamErrorException$, 0], [() => ValidationException$, 0], [() => ThrottlingException$, 0], [() => ModelTimeoutException$, 0], [() => ServiceUnavailableException$, 0]]
14001425
];
1426+
export var OutputFormatStructure$: StaticUnionSchema = [4, n0, _OFS,
1427+
8,
1428+
[_jS],
1429+
[() => JsonSchemaDefinition$]
1430+
];
14011431
export var PromptVariableValues$: StaticUnionSchema = [4, n0, _PVV,
14021432
0,
14031433
[_te],

0 commit comments

Comments
 (0)