**TextGrad** logo

**TextGrad**

Free

![](https://img.shields.io/github/stars/zou-group/textgrad?style=flat-square)

FreeFree tier
Inputs: text, imageOutputs: text
Type
Open Source

About **TextGrad**

TextGrad is an open-source framework that implements automatic differentiation via text feedback, using large language models (LLMs) to backpropagate textual gradients. It provides a PyTorch-like API, allowing users to define loss functions and optimize them using text-based gradients. The framework supports multiple LLMs through the litellm library, including OpenAI, Bedrock, Together, and Gemini, with caching control. Published in Nature, TextGrad enables backpropagation through text for tasks like reasoning, prompt optimization, and other text-based optimization problems. The API is intuitive for those familiar with PyTorch, making it easy to adapt to various use cases.

Key Features

Autograd engine for textual gradients using LLMs
Backpropagation through text feedback
PyTorch-like API for defining loss functions and optimization
Support for multiple LLMs via litellm (OpenAI, Bedrock, Together, Gemini)
Caching control for engine calls
Published in Nature (March 2025)
Open-source and free to use

Pros & Cons

Pros
  • Innovative approach to optimization via textual gradients
  • Familiar PyTorch-like API reduces learning curve
  • Supports a wide range of LLMs through litellm
  • Published in a top-tier scientific journal (Nature)
  • Open-source with no licensing costs
Cons
  • Requires access to external LLM APIs, incurring usage costs
  • Dependency on litellm engine which is still experimental
  • Textual gradients may be less precise than numeric gradients
  • Performance depends on the underlying LLM's quality

Best For

Optimizing LLM responses for reasoning problemsPrompt optimization and tuningText-based optimization in research and developmentAutomatic differentiation for tasks where gradients are textual

FAQ

What is TextGrad?
TextGrad is an open-source framework that implements automatic differentiation via text feedback, using LLMs to backpropagate textual gradients. It is inspired by the gradient metaphor from neural networks.
How does TextGrad work?
TextGrad allows you to define loss functions in natural language and optimize them by iteratively getting textual feedback from an LLM, similar to gradient descent but with text instead of numeric gradients.
Which LLMs are supported?
TextGrad supports any LLM available through the litellm library, including GPT-4o from OpenAI, models from Bedrock, Together, Gemini, and more. The engine is loaded with a prefix 'experimental:' (e.g., 'experimental:gpt-4o').
Is TextGrad free?
TextGrad is open-source and free to use, but you may need to pay for API calls to the underlying LLMs you use.
How do I get started?
Install TextGrad, set a backward engine using tg.set_backward_engine(), create a BlackboxLLM, define a loss function, and optimize by calling backward() on the loss. See the README for a quickstart example.