Registry / llm-agents / magentic

magentic

JSON →
library0.41.1pypypi✓ verified 26d ago

Decorator-based library for seamlessly integrating LLMs as Python functions. Uses @prompt, @chatprompt, and @prompt_chain decorators to turn Python function signatures into LLM calls with typed structured output. Built on pydantic for output validation. Current version: 0.41.1 (Mar 2026). Still pre-1.0 — API may change. Default backend: OpenAI.

pip install magentic
INSTALL
IMPORT
SIG · MAGENTIC
M
magentic
llm-agentspythonv0.41.1
Install
11.1s avg
Import
3487ms
Disk
70MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.41.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 12.6s
py 3.11
✓ —
✓ 11.23s
py 3.12
✓ —
✓ 10.23s
py 3.13
✓ —
✓ 10.37s
py 3.9
✕ build_error
✕ build_error
70MB installed
● package 70MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

prompt
from magentic import prompt
from magentic import prompt
chatprompt
from magentic import chatprompt
prompt_chain
from magentic import prompt_chain

Minimal magentic structured output using @prompt decorator.

# pip install magentic from magentic import prompt from pydantic import BaseModel class Superhero(BaseModel): name: str power: str enemies: list[str] @prompt('Create a superhero named {name}.') def create_superhero(name: str) -> Superhero: ... # never executed hero = create_superhero('Garden Man') print(hero.name) # 'Garden Man' print(hero.power) # 'Control over plants' print(hero.enemies) # ['Pollution Man', ...]
Debug
Known issues
gotchaThe function body of @prompt decorated functions is NEVER executed. Must use ... (ellipsis) as the body. Any actual code in the body is dead code that will never run.
fix
Always use '...' as the function body for @prompt, @chatprompt, @prompt_chain decorated functions.
affects: all
gotchaWhen functions= is passed to @prompt, the LLM may return a FunctionCall object instead of the final result. Must call fn_call() to execute it. Use @prompt_chain to auto-resolve.
fix
result = describe_weather('Boston')() — note the extra () to execute the FunctionCall. Or use @prompt_chain for automatic resolution.
affects: all
gotchaDefault model is gpt-4o-mini (OpenAI). Requires OPENAI_API_KEY. Fails silently if not set — raises AuthenticationError at call time, not at decoration time.
fix
Set OPENAI_API_KEY env var. Or pass model= explicitly: @prompt('...', model=OpenaiChatModel('gpt-4o'))
affects: all
gotchaStill pre-1.0 (0.41.x). API stability not guaranteed. Minor versions may introduce breaking changes.
fix
Pin version in production: pip install magentic==0.41.1
affects: all
gotchaAnthropic and LiteLLM backends require separate extras. 'pip install magentic' alone only includes OpenAI backend.
fix
pip install 'magentic[anthropic]' or 'magentic[litellm]'
affects: all
breakingmagentic requires Python >= 3.10. Installation will fail on older Python versions.
fix
Upgrade Python to 3.10 or newer.
affects: all
Upgrade
Version history
0.41.1latest on PyPI · released Mar 11, 2026
Audit
Dependencies
openairequiredDefault backend. Installed automatically with core package.
pydanticrequiredRequired for structured output validation.
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
magentic — pip install magentic · libregistry