Replace Ecto with Peri for schema validation#2
Merged
Conversation
Ecto's changeset pipeline was designed for casting external input into database-backed entities. Using it for pure in-memory structs caused friction: cast_embed rejected structs, two construction paths behaved differently, and a ~2MB persistence library was pulled in for simple map validation. Switch to Peri (lightweight schema validation) with plain defstruct. Each schema module now exports json_schema/0, replacing the Ecto introspection in the OpenAI adapter. ADR-0008 documents the rationale; ADR-0002 is marked superseded.
e958672 to
8350610
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
{:ecto, "~> 3.11"}for{:peri, "~> 0.3"}inmix.exsTestCaseandToolCallfrom Ecto embedded schemas to plaindefstruct+ Peridefschemajson_schema/0callbacksWhy
Ecto's changeset pipeline is designed for casting external input into database-backed entities. Using it purely for in-memory struct validation caused three problems:
cast_embedrejects structs — nested%ToolCall{}structs couldn't be passed throughTestCasechangesets; Ecto expects raw maps at cast time%TestCase{...}(direct struct) andTestCase.new!/1(changeset) behaved differently, forcing callers to know which to usePeri provides declarative schema validation on plain maps with no persistence assumptions.
Test plan
mix deps.getfetches Peri, removes Ectomix compile --warnings-as-errors— clean compile, no Ecto referencesmix test— all 125 tests passgrep -r "Ecto" lib/ test/— confirms no remaining Ecto references