Files
fil/docs/snippets/elixir/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

791 B

schema = %{
  "type" => "object",
  "properties" => %{
    "title" => %{"type" => "string"},
    "authors" => %{"type" => "array", "items" => %{"type" => "string"}},
    "date" => %{"type" => "string"}
  },
  "required" => ["title", "authors", "date"],
  "additionalProperties" => false
}

config_json =
  Jason.encode!(%{
    "structured_extraction" => %{
      "schema" => schema,
      "schema_name" => "paper_metadata",
      "strict" => true,
      "llm" => %{"model" => "openai/gpt-4o-mini"}
    }
  })

{:ok, json} = Kreuzberg.extract_file_async("paper.pdf", nil, config_json)
result = Jason.decode!(json)

case result["structured_output"] do
  nil -> IO.puts("no structured output")
  output -> IO.inspect(output, label: "structured")
end