Chatfield: Conversational Data Collection AI Agent
[!TIP]
🎥 Watch me develop this live.
Chatfield is a library to collect information using conversation rather than forms.
- Chatfield supports Python and TypeScript as well as JavaScript
- Chatfield supports Server and Browser operation
- Chatfield works in any User Interface because it computes what to say, now how to present
import { chatfield } from 'chatfield' // Or Python: from chatfield import chatfield
const trip = chatfield() // Identical API in Python and TypeScript/JavaScript
.field('destination')
.desc('Where would you like to go?')
.field('budget')
.desc('What is your budget?')
.build()
With Chatfield, your application can easily do:
- Natural Conversation: You tell Chatfield the user input. Chatfield tells you what to say in response.
- LLM-Powered Validation: Write rules in natural language describing valid or invalid field values.
- LLM-powered Data Transformation: "Cast" user input into any additional representation you want:
- Convert to data:
"5k" becomes 5000. "Yes" becomes true. "50/50" becomes 0.5
- Convert to object:
"I am Sam age 20" becomes {"name":"Sam", "age":20}
- Translate language:
"Hello" becomes "Bonjour"
- Classify user input into categories you choose
Chatfield works in any framework. Internally, Chatfield is built on LangGraph and LangChain, supporting all LLMs which LangChain supports.
Quick Start
Running the Travel Planner
Using the simple travel form defined above, here's how to run a conversation:
Python:
from chatfield import chatfield, Interviewer
# Define the travel planner (from above)
trip = (chatfield()
.field("destination")
.desc("Where would you like to go?")
.field("budget")
.desc("What is your budget?")
.build())
# Run the conversation
interviewer = Interviewer(trip)
user_input = None
while not trip._done:
message = interviewer.go(user_input)
print(message)
user_input = input("> ")
# Access collected data
print(f"Destination: {trip.destination}")
print(f"Budget: {trip.budget}")
TypeScript:
import { chatfield, Interviewer } from 'chatfield'
// Define the travel planner (from above)
const trip = chatfield()
.field('destination')
.desc('Where would you like to go?')
.field('budget')
.desc('What is your budget?')
.build()
// Run the conversation
const interviewer = new Interviewer(trip)
let userInput: string | null = null
while (!trip._done) {
const message = await interviewer.go(userInput)
console.log(message)
userInput = await getUserInput() // Your input method
}
// Access collected data
console.log(`Destination: ${trip.destination}`)
console.log(`Budget: ${trip.budget}`)
Chatfield as a Claude Code Plugin
The Chatfield Claude Code Marketplace includes a plugin to complete PDF forms through conversation.
Add the Chatfield Marketplace
/plugin marketplace add jhs/Chatfield
Add the Chatfield PDF plugin
/plugin install filling-pdf-forms@jhs/Chatfield
To use, /pdf path/to/form.pdf or just ask "Help me complete this PDF form"
The plugin understands form fields, interviews you conversationally, and produces a completed .done.pdf file.
Chatfield supports both fillable and non-fillable PDFs, with text content or without text content.
If the form is not the language you speak, Chatfield will speak your language and translate for you.
Core Concepts
Chatfield transforms traditional form fields into conversational topics. The AI interviewer guides users through data collection naturally, validating responses and transforming them into structured data.
Field Definition
Fields are the basic building blocks. Each field represents a piece of data to collect:
Python:
trip = (chatfield()
.field("destination")
.desc("Where would you like to go?")
.field("travel_style")
.desc("What's your travel style?")
.field("group_size")
.desc("How many people are traveling?")
.build())
TypeScript:
const trip = chatfield()
.field('destination')
.desc('Where would you like to go?')
.field('travelStyle')
.desc('What\'s your travel style?')
.field('groupSize')
.desc('How many people are traveling?')
.build()
Interview Metadata
Provide context about your interview: