Repolode
knowsuchagency

knowsuchagency/promptic

A lightweight Python decorator library that turns docstrings into LLM prompts, with Pydantic outputs, tool calling, streaming and memory, built on LiteLLM.

Stars
272
Forks
24
Open issues
0
Last commit
26 days ago

What is it?

Promptic is a small Python library for building LLM applications. You decorate a function with @llm, and its docstring becomes the prompt template, filled in with the function's arguments. The call returns the model's response directly, so a function can act as a prompt without manual request handling.

Under the hood it uses LiteLLM, so the same code can target OpenAI, Anthropic, Gemini, Azure and other providers by changing the model name. Return type annotations can be Pydantic models or JSON Schema dictionaries, and responses are validated against them. Functions decorated with @llm.tool are exposed to the model as callable tools.

The library also covers image inputs through an ImageBytes type, streaming responses, optional conversation memory with a pluggable State class, Anthropic prompt caching controls, and Weave tracing integration. It is designed to stay thin, so the underlying provider SDKs remain accessible.

Key features

  • 01Turns function docstrings into prompt templates via the @llm decorator.
  • 02Validates structured outputs against Pydantic models or JSON Schema.
  • 03Supports tool calling with functions registered through @llm.tool.
  • 04Streams responses and accepts image inputs as ImageBytes.
  • 05Offers optional conversation memory with a customizable State class.

Use cases

  • Prototyping LLM features in Python without writing request boilerplate.
  • Extracting typed data from text or images into Pydantic objects.
  • Building a simple chatbot or agent that calls Python functions as tools.
  • Switching between LLM providers without rewriting application code.

Quick start

  1. 1

    Install promptic from PyPI

    pip install promptic
  2. 2

    Set your LLM provider API key as an environment variable (example for OpenAI)

    export OPENAI_API_KEY=sk-...
  3. 3

    Decorate a function with @llm, using its docstring as the prompt, and call it

Things to know

  • Requires an API key from an LLM provider (such as OpenAI or Anthropic) or a compatible model setup.

In collections

Topics

FAQ

What is promptic?
A lightweight Python decorator library that turns docstrings into LLM prompts, with Pydantic outputs, tool calling, streaming and memory, built on LiteLLM. Promptic is a small Python library for building LLM applications. You decorate a function with @llm, and its docstring becomes the prompt template, filled in with the function's arguments. The call returns the model's response directly, so a function can act as a prompt without manual request handling.
Is promptic free to use? What license does it have?
promptic is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is promptic still maintained?
Actively maintained. The last commit to promptic was on Oct 12, 2026.
What can I use promptic for?
Prototyping LLM features in Python without writing request boilerplate. Extracting typed data from text or images into Pydantic objects. Building a simple chatbot or agent that calls Python functions as tools. Switching between LLM providers without rewriting application code.
How do I install promptic?
Install promptic from PyPI: pip install promptic Set your LLM provider API key as an environment variable (example for OpenAI): export OPENAI_API_KEY=sk-... Decorate a function with @llm, using its docstring as the prompt, and call it
Where can I get promptic?
The source code and installation instructions are on GitHub: https://github.com/knowsuchagency/promptic

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects