LLM-Optimized Reference
Compressed single-page reference for LLM code-generation tools. Contains all public signatures, types, and usage patterns.
Package
using DescribedTypes
# Exports: schema, Annotation, annotate, LLMAdapter, STANDARD, OPENAI, OPENAI_TOOLS, GEMINITypes
LLMAdapter
@enum LLMAdapter STANDARD OPENAI OPENAI_TOOLS GEMINISelects the LLM-provider schema format:
STANDARD— plain JSON Schema (no wrapping).OPENAI— OpenAI structured-output response format; wraps schema under"schema"key, setsstrict: true,additionalProperties: false, all fields required (optional →["type", "null"]).OPENAI_TOOLS— OpenAI function/tool calling; wraps schema under"parameters"key with"type": "function", same strict rules asOPENAI.GEMINI— placeholder for Google Gemini format.
Annotation
Base.@kwdef struct Annotation
name::String
description::String = ""
markdown::String = ""
enum::Union{Nothing, Vector{String}} = nothing
parameters::Union{Nothing, Dict{Symbol, Annotation}} = nothing
end
Annotation(name::String) # convenience; auto-generates descriptionMetadata for a Julia type or field used during JSON Schema generation.
name— display name in schema.description— human-readable description.markdown— optional Markdown docs.enum— constrained string values (appears as"enum"in schema).parameters— per-fieldAnnotationkeyed by field name (Symbol).
Functions
annotate
annotate(::Type{T}) -> AnnotationOverride per type to attach metadata:
DescribedTypes.annotate(::Type{MyStruct}) = Annotation(
name = "MyStruct",
description = "Short description.",
parameters = Dict(
:field1 => Annotation(name="field1", description="Field 1 description"),
:field2 => Annotation(name="field2", description="Field 2 description", enum=["a", "b"]),
),
)Default fallback uses string(T) as name with generic field descriptions.
schema
schema(
schema_type::Type;
use_references::Bool = false,
dict_type::Type{<:AbstractDict} = JSON.Object,
llm_adapter::LLMAdapter = STANDARD
) -> AbstractDict{String, Any}Generates a JSON Schema dictionary from a Julia type.
Keyword arguments:
use_references— whentrue, nested struct types are factored into$defsand referenced via$ref.dict_type— dictionary type for the output (defaultJSON.Objectfor ordered keys).llm_adapter— schema format selector (seeLLMAdapter).
Return shape by adapter:
llm_adapter | Top-level keys |
|---|---|
STANDARD | type, properties, required [, $defs] |
OPENAI | name, description, strict, schema → {schema object} |
OPENAI_TOOLS | type="function", name, description, strict, parameters → {schema object} |
Patterns
Define a type and annotate it
struct Weather
location::String
temperature::Float64
unit::String
end
DescribedTypes.annotate(::Type{Weather}) = Annotation(
name = "Weather",
description = "Current weather observation.",
parameters = Dict(
:location => Annotation(name="location", description="City name"),
:temperature => Annotation(name="temperature", description="Temperature value"),
:unit => Annotation(name="unit", description="Unit of measurement",
enum=["celsius", "fahrenheit"]),
),
)Generate schemas
using JSON
# Plain JSON Schema
schema(Weather)
# OpenAI structured output (response_format)
schema(Weather, llm_adapter=OPENAI)
# OpenAI tool/function calling
schema(Weather, llm_adapter=OPENAI_TOOLS)
# With $defs for nested types
schema(Weather, use_references=true)Optional fields
Use Union{Nothing, T}. In STANDARD mode the field is not in required. In OPENAI/OPENAI_TOOLS mode the field stays required but its type becomes ["type", "null"].
struct Query
text::String
max_results::Union{Nothing, Int}
endNested structs
struct Address
street::String
city::String
end
struct Person
name::String
address::Address
endNested structs are inlined by default. Pass use_references=true to factor them into $defs.
Enums
Julia @enum types map to "type": "string" with "enum" values automatically. Field-level enums can also be set via the enum kwarg in Annotation.
Serializing to JSON string
import JSON
JSON.json(schema(MyType), 2) # pretty-printed
JSON.json(schema(MyType, llm_adapter=OPENAI)) # compactSupported Julia type mappings
| Julia type | JSON Schema type |
|---|---|
String / AbstractString | string |
Bool | boolean |
<:Integer | integer |
<:Real | number |
Nothing / Missing | null |
<:AbstractArray | array |
<:Enum | string + enum |
Any other struct | object |