CouncilEx.Schema.JSONSchema (CouncilEx v0.1.0)

Copy Markdown View Source

Convert an Ecto embedded schema to a JSON Schema map.

Vendored replacement for Instructor.JSONSchema.from_ecto_schema/1 covering the types CouncilEx actually uses: primitives, arrays of primitives, embeds_one/embeds_many. User schemas needing exotic types (decimals, datetimes, custom Ecto types) implement __json_schema__/0 to bypass auto-generation entirely.

Strict mode: additionalProperties: false. Required-fields detection: a field is required iff it has no default: opt and isn't an embeds_many (which defaults to []).

Summary

Functions

Convert an Ecto embedded schema module to a JSON Schema map.

Functions

from_ecto_schema(schema)

@spec from_ecto_schema(module() | {:json_schema, map()}) :: map()

Convert an Ecto embedded schema module to a JSON Schema map.

Also accepts the inline {:json_schema, map} form used by dynamic councils — returns the map unchanged. Lets every adapter that calls this function (OpenAI, Anthropic, Gemini) transparently support both Ecto schemas and pre-built JSON Schema maps without changes.