Ecto field descriptions

These are great suggestions. In my particularly usecase I found an easier way to go about it.

I’m working on the GitHub - thmsmlr/instructor_ex: Structured outputs for LLMs in Elixir · GitHub library and the JSONSchema is getting sent into an LLM. What I realized is that the LLM should be resilient to whether the description is at the schema level or the field level. So I decided to just do something like,

defmodule SpamPredicition do
  use Ecto.Schema
  use Instructor.Validator

  @doc """
  ## Field Descriptions:
  - class: Whether or not the email is spam
  - reason: A short, less than 10 word rationalization for the classification
  - score: A confidence score between 0.0 and 1.0 for the classification
  """
  @primary_key false
  embedded_schema do
    field(:class, Ecto.Enum, values: [:spam, :not_spam])
    field(:reason, :string)
    field(:score, :float)
  end

In some sense, for my usecase, this is even more flexible because you can write whatever you want about the semantics of this schema in the schema level @doc and the AI can make the appropriate associations, since you know.. it’s AI or whatnot.

If I come back to this under other circumstances i’ll definitely explore these solutions. Thanks y’all for your help!