AxSignatureBuilder Generated TypeScript API reference. typescript api api/reference build/apidocs/Class.AxSignatureBuilder.md class AxSignatureBuilder

AxSignatureBuilder

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/dsp/sig.ts#L72

Type Parameters

Type ParameterDefault type
_TInput extends Record<string, any>object
_TOutput extends Record<string, any>object

Constructors

Constructor

TypeScript
new AxSignatureBuilder<_TInput, _TOutput>(): AxSignatureBuilder<_TInput, _TOutput>;

Returns

AxSignatureBuilder<_TInput, _TOutput>

Methods

addInputFields()

TypeScript
addInputFields(fields: readonly AxIField[]): AxSignatureBuilder<Record<string, any>, _TOutput>;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/dsp/sig.ts#L218

Add pre-existing input fields (e.g., extracted from another signature). Type safety is lost for these fields since they are dynamically defined.

Parameters

ParameterType
fieldsreadonly AxIField[]

Returns

AxSignatureBuilder<Record<string, any>, _TOutput>


addOutputFields()

TypeScript
addOutputFields(fields: readonly AxIField[]): AxSignatureBuilder<_TInput, Record<string, any>>;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/dsp/sig.ts#L231

Add pre-existing output fields (e.g., extracted from another signature). Type safety is lost for these fields since they are dynamically defined.

Parameters

ParameterType
fieldsreadonly AxIField[]

Returns

AxSignatureBuilder<_TInput, Record<string, any>>


build()

TypeScript
build(): AxSignature<_TInput, _TOutput>;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/dsp/sig.ts#L266

Build the final AxSignature instance

Returns

AxSignature<_TInput, _TOutput>


description()

TypeScript
description(description: string): AxSignatureBuilder<_TInput, _TOutput>;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/dsp/sig.ts#L244

Set the description for the signature

Parameters

ParameterTypeDescription
descriptionstringDescription text

Returns

AxSignatureBuilder<_TInput, _TOutput>


input()

Call Signature

TypeScript
input<K, T>(
   name: K, 
   fieldInfo: T, 
prepend?: boolean): AxSignatureBuilder<AddFieldToShape<_TInput, K, T, "input">, _TOutput>;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/dsp/sig.ts#L102

Add an input field to the signature. Three shapes:

  1. Native fluent field.input('name', f.string()). Supports every LLM-optimized affordance (.cache(), .internal(), multimodal, etc.).
  2. Per-field Standard Schema.input('name', z.string().min(3), { cache: true }). Pass any zod/valibot/arktype schema. Companion opts adds ax-specific hints (cache, internal) that schema libraries don’t represent.
  3. Whole-object Standard Schema.input(z.object({...}), { fields: { ctx: { cache: true } } }). Decomposed into per-key fields in declaration order.
Example
TypeScript
f()
  .input(z.object({
    context: z.string(),
    question: z.string().describe('User question'),
  }), { fields: { context: { cache: true } } })
  .output('answer', f.string())
  .build();
Type Parameters
Type Parameter
K extends string
T extends | AxFluentFieldInfo<any, any, any, any, any, any, any> | AxFluentFieldType<any, any, any, any, any, any, any>
Parameters
ParameterType
nameK
fieldInfoT
prepend?boolean
Returns

AxSignatureBuilder<AddFieldToShape<_TInput, K, T, "input">, _TOutput>

Call Signature

TypeScript
input<K, T>(
   name: K, 
   schema: T, 
opts?: AxFieldOptions): AxSignatureBuilder<_TInput & { [P in string]: InferOutput<T> }, _TOutput>;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/dsp/sig.ts#L112

Add an input field to the signature. Three shapes:

  1. Native fluent field.input('name', f.string()). Supports every LLM-optimized affordance (.cache(), .internal(), multimodal, etc.).
  2. Per-field Standard Schema.input('name', z.string().min(3), { cache: true }). Pass any zod/valibot/arktype schema. Companion opts adds ax-specific hints (cache, internal) that schema libraries don’t represent.
  3. Whole-object Standard Schema.input(z.object({...}), { fields: { ctx: { cache: true } } }). Decomposed into per-key fields in declaration order.
Example
TypeScript
f()
  .input(z.object({
    context: z.string(),
    question: z.string().describe('User question'),
  }), { fields: { context: { cache: true } } })
  .output('answer', f.string())
  .build();
Type Parameters
Type Parameter
K extends string
T extends StandardSchemaV1<unknown, unknown>
Parameters
ParameterType
nameK
schemaT
opts?AxFieldOptions
Returns

AxSignatureBuilder<_TInput & { [P in string]: InferOutput<T> }, _TOutput>

Call Signature

TypeScript
input<T>(schema: T, opts?: object): AxSignatureBuilder<AsRecord<InferOutput<T>>, _TOutput>;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/dsp/sig.ts#L120

Add an input field to the signature. Three shapes:

  1. Native fluent field.input('name', f.string()). Supports every LLM-optimized affordance (.cache(), .internal(), multimodal, etc.).
  2. Per-field Standard Schema.input('name', z.string().min(3), { cache: true }). Pass any zod/valibot/arktype schema. Companion opts adds ax-specific hints (cache, internal) that schema libraries don’t represent.
  3. Whole-object Standard Schema.input(z.object({...}), { fields: { ctx: { cache: true } } }). Decomposed into per-key fields in declaration order.
Example
TypeScript
f()
  .input(z.object({
    context: z.string(),
    question: z.string().describe('User question'),
  }), { fields: { context: { cache: true } } })
  .output('answer', f.string())
  .build();
Type Parameters
Type Parameter
T extends StandardSchemaV1<unknown, unknown>
Parameters
ParameterType
schemaT
opts?{ fields?: Record<string, AxFieldOptions>; }
opts.fields?Record<string, AxFieldOptions>
Returns

AxSignatureBuilder<AsRecord<InferOutput<T>>, _TOutput>


output()

Call Signature

TypeScript
output<K, T>(
   name: K, 
   fieldInfo: T, 
prepend?: boolean): AxSignatureBuilder<_TInput, AddFieldToShape<_TOutput, K, T, "output">>;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/dsp/sig.ts#L160

Add an output field to the signature. Same three shapes as AxSignatureBuilder.input.

Type Parameters
Type Parameter
K extends string
T extends | AxFluentFieldInfo<any, any, any, any, any, any, any> | AxFluentFieldType<any, any, any, any, any, any, any>
Parameters
ParameterType
nameK
fieldInfoT
prepend?boolean
Returns

AxSignatureBuilder<_TInput, AddFieldToShape<_TOutput, K, T, "output">>

Call Signature

TypeScript
output<K, T>(
   name: K, 
   schema: T, 
opts?: AxFieldOptions): AxSignatureBuilder<_TInput, _TOutput & { [P in string]: InferOutput<T> }>;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/dsp/sig.ts#L170

Add an output field to the signature. Same three shapes as AxSignatureBuilder.input.

Type Parameters
Type Parameter
K extends string
T extends StandardSchemaV1<unknown, unknown>
Parameters
ParameterType
nameK
schemaT
opts?AxFieldOptions
Returns

AxSignatureBuilder<_TInput, _TOutput & { [P in string]: InferOutput<T> }>

Call Signature

TypeScript
output<T>(schema: T, opts?: object): AxSignatureBuilder<_TInput, AsRecord<InferOutput<T>>>;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/dsp/sig.ts#L178

Add an output field to the signature. Same three shapes as AxSignatureBuilder.input.

Type Parameters
Type Parameter
T extends StandardSchemaV1<unknown, unknown>
Parameters
ParameterType
schemaT
opts?{ fields?: Record<string, AxFieldOptions>; }
opts.fields?Record<string, AxFieldOptions>
Returns

AxSignatureBuilder<_TInput, AsRecord<InferOutput<T>>>


useStructured()

TypeScript
useStructured(): AxSignatureBuilder<_TInput, _TOutput>;

Defined in: https://github.com/ax-llm/ax/blob/5b28f9093bb70863b59459bb6df5062d005bce41/src/ax/dsp/sig.ts#L254

Enforce structured outputs (JSON) for this signature, even if fields are simple.

Returns

AxSignatureBuilder<_TInput, _TOutput>

Docs