Form

Form#

Gives the assistant the ability to present a form with multiple fields for user input.

This tool enables structured data collection from users through an interactive form with support for different field types: text, select, boolean, and number.

Instructions

### When to use the form tool

Use the form tool when you need to collect multiple related fields from the
user in a single interaction. It is well suited for structured data collection
where field types are text, select (choose from a list), boolean (yes/no), or
number.

For **secrets** (API keys, passwords) use the ``elicit`` tool instead — form
does not have a secret type, so credentials would appear in the chat display.

For a single question or free-form input, a plain assistant message is simpler.
Prefer form when collecting two or more related fields at once.

### Form syntax

Each field is specified on a separate line with the format:
  field_name: Prompt text [options]

Field types are inferred from the prompt:
- Text field (default): `name: What's your name?`
- Select field: `priority: Priority level [low, medium, high]`
- Boolean field: `confirm: Are you sure? [yes/no]`
- Number field: `count: How many? (number)`

The tool will present an interactive form and return the collected data as JSON.

Examples

Collect project information

User
I want to start a new project
Assistant
Let me gather some information about your project:
form
name: Project name?
description: Brief description?
language: Primary language [python, javascript, rust, go, other]
priority: Priority level [low, medium, high]
System
Form submitted:
json
{"name": "my-awesome-project", "description": "A CLI tool for productivity", "language": "python", "priority": "high"}

Simple confirmation form

User
Deploy to production
Assistant
Please confirm the deployment details:
form
environment: Target environment [staging, production]
confirm: Proceed with deployment? [yes/no]
System
Form submitted:
json
{"environment": "production", "confirm": true}
gptme.tools.form.execute_form(code: str | None, args: list[str] | None, kwargs: dict[str, str] | None) Generator[Message, None, None]

Present a form to the user and collect their responses.

gptme.tools.form.parse_field(line: str) dict | None

Parse a field definition line into a field specification.

gptme.tools.form.parse_form_content(content: str) list[dict]

Parse form content into a list of field specifications.