Method WithOutputSchema
WithOutputSchema(string)
Constrains every answer of the agent to a JSON Schema, enforced while decoding: the model may still call tools, and its final answer is a JSON document that conforms to the schema.
public AgentBuilder WithOutputSchema(string jsonSchema)
Parameters
jsonSchemastringThe JSON Schema text (an object schema);
nullor empty for free text.
Returns
- AgentBuilder
This builder instance for method chaining.
Examples
var agent = Agent.CreateBuilder(model)
.WithInstruction("Triage the support ticket.")
.WithOutputSchema(@"{""type"":""object"",""properties"":{""reply"":{""type"":""string""},""needs_human"":{""type"":""boolean""}},""required"":[""reply"",""needs_human""]}")
.Build();
Exceptions
- ArgumentException
Thrown when the schema cannot constrain an answer.