Files
fil/docs/snippets/csharp/llm/structured_extraction.md
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

928 B

using Kreuzberg;
using System.Text.Json;
using System.Text.Json.Nodes;

var schema = JsonNode.Parse("""
{
    "type": "object",
    "properties": {
        "title": { "type": "string" },
        "authors": { "type": "array", "items": { "type": "string" } },
        "date": { "type": "string" }
    },
    "required": ["title", "authors", "date"],
    "additionalProperties": false
}
""")!;

var config = new ExtractionConfig
{
    StructuredExtraction = new StructuredExtractionConfig
    {
        Schema = schema,
        SchemaName = "paper_metadata",
        Strict = true,
        Llm = new LlmConfig
        {
            Model = "openai/gpt-4o-mini",
        },
    },
};

var result = await KreuzbergLib.ExtractFile("paper.pdf", null, config);

if (result.StructuredOutput is not null)
{
    Console.WriteLine(JsonSerializer.Serialize(result.StructuredOutput));
}