feat(pydantic): add ToonPydanticModel with schema_to_toon() and from_toon()#46
Open
Ansarafsar wants to merge 1 commit intotoon-format:mainfrom
Open
feat(pydantic): add ToonPydanticModel with schema_to_toon() and from_toon()#46Ansarafsar wants to merge 1 commit intotoon-format:mainfrom
Ansarafsar wants to merge 1 commit intotoon-format:mainfrom
Conversation
Contributor
|
LGTM README-wise, the rest is up to the @toon-format/python-maintainers. :) |
johannschopplich
approved these changes
Nov 29, 2025
Author
|
Thank you @*johannschopplich :)*
…On Sat, 29 Nov 2025 at 14:34, Johann Schopplich ***@***.***> wrote:
***@***.**** approved this pull request.
—
Reply to this email directly, view it on GitHub
<#46 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AT5UVZBLT4AHBJAGVYG3Y7337FOTDAVCNFSM6AAAAACNPXFJ2WVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTKMRQGYYDKOJQGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Author
|
Hi @toon-format/python-maintainers just a small follow up request on merging the PR :) |
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.
Description
Adds first-class Pydantic integration via an optional [
pydantic] extra. Users can install withpip install "toon-python[pydantic]"and inherit fromToonPydanticModelto get.schema_to_toon()(ultra-compact schema for prompts) and.from_toon()(parse raw TOON output directly into a validated model). Saves 50–60% tokens on schemas and eliminates JSON parsing errors completely.Key methods:
schema_to_toon()- Convert Pydantic schema to compact TOON formatfrom_toon()- Parse LLM TOON output into validated model instancesType of Change
Related Issues
Part of #44 (Agent framework integration – Pydantic AI request)
Changes Made
src/toon_format/pydantic/withToonPydanticModelmixintests/test_pydantic.pywith 4 comprehensive tests[pydantic]extra inpyproject.tomlREADME.mdwith clear installation + usage examplesSPEC Compliance
(Uses existing
encode/decode– 100 % spec-compliant)Testing
Test Output
Code Quality
ruff check src/toon_format tests– no issuesruff format src/toon_format tests– code formattedmypy src/toon_format– no critical errorspytest tests/ -vChecklist
Performance Impact
Breaking Changes
Screenshots / Examples
Additional Context
This + the already-open LangChain PR completes the two most requested agent-framework integrations from discussion #44.
TOON is now the cheapest, most reliable format for structured LLM output in 2025 – works perfectly with Instructor, Outlines, Marvin, LangChain agents, etc.
Fully optional – core users completely unaffected.
Thank you for the quick review – let’s make TOON the default for AI engineering!