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 magenticVerified import paths — ran on the pinned version, not inferred.
Minimal magentic structured output using @prompt decorator.
Always use '...' as the function body for @prompt, @chatprompt, @prompt_chain decorated functions.
result = describe_weather('Boston')() — note the extra () to execute the FunctionCall. Or use @prompt_chain for automatic resolution.Set OPENAI_API_KEY env var. Or pass model= explicitly: @prompt('...', model=OpenaiChatModel('gpt-4o'))Pin version in production: pip install magentic==0.41.1
pip install 'magentic[anthropic]' or 'magentic[litellm]'
Upgrade Python to 3.10 or newer.