DescribedTypes.jl

Annotate Julia types with descriptions and generate JSON Schemas for LLM provider APIs.

Overview

DescribedTypes.jl lets you attach human-readable descriptions to Julia struct types and their fields, then automatically produces JSON Schema dictionaries compatible with LLM structured-output APIs.

Supported adapters:

AdapterUse caseWrapper key
STANDARDPlain JSON Schema (no wrapping)
OPENAIStructured output via response_format"schema"
OPENAI_TOOLSFunction / tool calling"parameters"
GEMINIGoogle Gemini (placeholder)

Installation

using Pkg
Pkg.add("DescribedTypes")

Or in the Pkg REPL:

pkg> add DescribedTypes

Quick Start

using DescribedTypes
using JSON

struct Person
    name::String
    age::Int
end

DescribedTypes.annotate(::Type{Person}) = Annotation(
    name="Person",
    description="A person.",
    parameters=Dict(
        :name => Annotation(name="name", description="The person's name", enum=["Alice", "Bob"]),
        :age  => Annotation(name="age", description="The person's age"),
    ),
)

# OpenAI structured-output format
schema_dict = schema(Person, llm_adapter=OPENAI)
print(JSON.json(schema_dict, 2))
{
  "name": "Person",
  "description": "A person.",
  "strict": true,
  "schema": {
    "type": "object",
    "properties": {
      "name": {
        "type": "string",
        "description": "The person's name",
        "enum": [
          "Alice",
          "Bob"
        ]
      },
      "age": {
        "type": "integer",
        "description": "The person's age"
      }
    },
    "required": [
      "name",
      "age"
    ],
    "additionalProperties": false
  }
}

See the Guide for more detailed usage and examples.