Formatters¶
Formatters convert your structured objects into LLM-readable text formats.
Auto-detection¶
The easiest way is to use auto_formatter_for_type:
from sintezi.ai.formatter import auto_formatter_for_type
formatter = auto_formatter_for_type(MyModel)
This automatically selects the best formatter based on your model structure:
- For regular Pydantic
BaseModelclasses, it uses JSON formatter - For
pydantic-xmlBaseXmlModelclasses, it uses XML formatter - For plain
strtypes, it passes them through directly
Available formatters¶
JSON¶
Most compatible with OpenAI's structured output format. Optionally pass indent=2 for pretty-printed output.
XML¶
Requires pydantic-xml. Useful for complex nested structures.
Plain text¶
For simple string-based inputs.
Custom formatters¶
Implement RequestFormatter[T]:
from sintezi.ai.formatter import RequestFormatter
from typing import TypeVar
T = TypeVar("T")
class MyCustomFormatter(RequestFormatter[T]):
def format(self, content: T) -> str:
return str(content)
Next steps¶
- Parsers — parsing LLM responses
- API Reference — complete formatter API