Claudia icon indicating copy to clipboard operation
Claudia copied to clipboard

JSON Structured Output

Open justintoth opened this issue 5 months ago • 0 comments

Thanks for providing this library. I was wondering how to go about defining the JSON structured output that the Claude response should adhere to.

For example, with OpenAI I can do this:

var jsonSchema = GetOpenAiOutputSchema(args);
completionOptions.ResponseFormat = ChatResponseFormat.CreateJsonSchemaFormat(
				jsonSchemaFormatName: args.OutputSchemaName,
				jsonSchema: BinaryData.FromBytes(Encoding.UTF8.GetBytes(jsonSchema)),
				jsonSchemaIsStrict: true);

private string GetOpenAiOutputSchema(GenAiMessageArgs args)
{
	var schemaBuilder = new JsonSchemaBuilder();
	var schema = schemaBuilder
		.FromType(args.OutputSchemaType)
		.Build();
	var json = JsonExtensions.Serialize(schema, prettyPrint: true);
	return json;
}

Does your package provide something similar? Or do I need to just include the JSON structured output in the actual user / system message prompt?

justintoth avatar Sep 17 '25 13:09 justintoth