Skip to main content
Abstract Formatter interface for rendering components to strings. A Formatter converts [Component](base#class-component) and [CBlock](base#class-cblock) objects into the text strings fed to language model prompts. The single abstract method print encapsulates this rendering contract; concrete subclasses such as [ChatFormatter](../formatters/chat_formatter#class-chatformatter) and [TemplateFormatter](../formatters/template_formatter#class-templateformatter) extend it with chat-message and Jinja2-template rendering respectively.

Classes

CLASS Formatter

A Formatter converts Components into strings and parses ModelOutputThunks into Components (or CBlocks).
Methods:

FUNC print

print(self, c: Component | CBlock) -> str
Renders a [Component](base#class-component) or [CBlock](base#class-cblock) into a string suitable for use as model input. Args:
  • c: The component or content block to render.
Returns:
  • The rendered string representation of c.