-
Notifications
You must be signed in to change notification settings - Fork 135
Communicate Validation Errors to Agent Prior to Form Submission #139
Description
In the declarative form API, it seems limiting that an agent gets no feedback about the state of a form without either:
- Looking at the DOM directly.
- Attempting to submit the form.
If the users asks it to fill out a form with some data, it has no inherent visibility into whether or not that was successful. Best case it can hope for is that the app renders such validation errors directly to the DOM and that a subsequent check will find it, but this is generally inefficient (requires more tokes, time, etc.). It also won't catch asynchronous validations, which could take an unbounded length of time and the agent doesn't know how long to wait.
The browser can probably expose built-in form validation APIs (ex. <input required minlength="5">), and I think that's a great default. We should probably also consider communicating those constraints to the generated inputSchema. But ultimately I think this falls well short of the complexity of modern form systems, which need to express much more complex constraints not immediately visible to the DOM.
Following from SubmitEvent.prototype.respondWith, is there a similar way we can expose validation information to an agent directly without requiring it to submit the form first? Maybe we could put this on toolactivated? This might require an additional field to know if the form is about to be submitted (or maybe this tells the agent to abort submit and does emit the submit event?).
navigator.modelContext.addEventListener('toolactivated', (evt: ToolActivatedEvent) => {
if (!evt.autosubmit) evt.repondWith(getMyErrorsForForm(evt.form));
});This would allow the agent to wait until asynchronous validations have completed (Is this username already taken in the database?) and give it immediate feedback without requiring it to manually query the DOM and attempt to determine the current form state.
I suspect this might also give the agent and user much more confidence that a given form is filled out as intended. It is likely helpful to the workflow to have the agent fill out a form, check its validity, and then later decide if it wants to submit. The alternative of immediately committing to form submission without necessarily knowing what will be validated could be a seen as a bit "scary" both for the user and the agent and make them both more hesitant to move forward with the action.