Skip to content

API Reference parrot_formdesigner.tools.edit_toolkit

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.tools.edit_toolkit

View source

EditToolkit — LLM-callable toolkit for surgical FormSchema editing.

Implements FEAT-169: instead of sending the full FormSchema JSON to the LLM, this toolkit exposes focused tools that allow the LLM to inspect and mutate the form in surgical, targeted operations. FEAT-393 (Module 6) re-addresses every mutation tool by field_uid/section_uid instead of field_id/ section_id.

Tool categories (see get_tools()/get_tool_definitions() for the authoritative, current list — do not hardcode a count here, it drifts):

  • Inspection: get_form_summary, get_section, get_field, search_fields
  • Field mutation: update_field, add_field, add_field_from_schema, remove_field, move_field
  • Dependency mutation: add_dependency, update_dependency, remove_dependency, add_post_dependency, remove_post_dependency
  • Section mutation: add_section, add_section_from_schema, update_section, update_section_title
  • Form-level mutation: update_form_meta, update_form_title, update_form_description
  • Control: done

Alias AddField

Re-exported from parrot_formdesigner.api.operations.AddField.

Alias AddSection

Re-exported from parrot_formdesigner.api.operations.AddSection.

Alias DependencyRule

Re-exported from parrot_formdesigner.core.constraints.DependencyRule.

Class EditToolkit

Toolkit exposing FormSchema inspection and mutation as LLM-callable tools.

The toolkit manages a deep copy of the FormSchema as its working state. Inspection tools read from this copy; mutation tools modify it via the operations.py apply functions (reusing all existing validation logic).

The LLM never sees the full form JSON — it uses get_form_summary to understand the structure, inspection tools to examine specific elements, and mutation tools to apply targeted changes. When all edits are complete the LLM calls done and the caller retrieves the updated form via the form property.

Usage::

toolkit = EditToolkit(form)
tools = toolkit.get_tools()           # List[AbstractTool]
# Pass tools to GoogleGenAIClient.ask(tools=tools, use_tools=True, ...)
updated_form = toolkit.form           # Retrieve after done() is called
Parameter Type Default Description
form FormSchema The FormSchema to edit. A deep copy is made immediately so the original is never mutated.
**kwargs Any {} Forwarded to AbstractToolkit.init.

Attributes:

Attribute Type Description
exclude_tools tuple[str, ...]
form FormSchema Current state of the working copy after all mutations.
is_done bool True after the LLM has called the done tool.

Method EditToolkit.get_form_summary

Return a compact outline of the form structure.

The summary includes form-level metadata and a condensed view of each section: section_id/section_uid, title, and for each field only field_id/field_uid, label, and field_type. Options, constraints, children, and meta are omitted to keep the response small (at most 5% of the full JSON for large forms).

field_uid (FEAT-393) is the immutable identity to pass into update_field/remove_field/move_field/get_field; field_id stays the human-readable key for rule authoring (add_dependency/add_post_dependency).

get_form_summary() -> dict

Returns: dict — Compact dict with form outline including section/field uid+id pairs and types.

Method EditToolkit.get_section

Return the full JSON for a single section by section_id.

get_section(section_id: str) -> dict

Parameter Type Default Description
section_id str ID of the section to retrieve.

Returns: dict — Full section data dict, or an error dict if not found.

Method EditToolkit.get_field

Return the full JSON for a single field by field_uid.

Searches the entire form, including subsections and nested GROUP/ARRAY fields (FEAT-393).

get_field(field_uid: str) -> dict

Parameter Type Default Description
field_uid str UUID string of the field to retrieve — obtain from get_form_summary or search_fields. Example: "3c3b0847-56fb-493f-bb84-2554b502a31e".

Returns: dict — Full field data dict with containing section_uid/ section_id, or an error dict.

Method EditToolkit.search_fields

Search for fields matching a label substring, type, or ID pattern.

The query is matched as:

  1. Case-insensitive substring of the field label
  2. Exact field_id match
  3. Regex match on field_id

search_fields(query: str, field_type: str | None = None) -> list[dict]

Parameter Type Default Description
query str Substring or regex pattern to search for in field labels/IDs.
field_type str | None None Optional field type filter (e.g. "text", "email").

Returns: list[dict] — List of match dicts with section_id, field_id, field_uid (str, FEAT-393 — feed this into update_field/remove_field/move_field/ get_field), label, field_type.

Method EditToolkit.update_field

Apply an RFC 7396 merge-patch to a single field, addressed by UID.

Keys present in patch override the existing value; keys absent in patch are preserved; explicit null values remove the key. patch MAY rename field_id (subject to per-form uniqueness); a patch touching field_uid is rejected — the identity is immutable.

update_field(section_uid: str, field_uid: str, patch: dict) -> dict

Parameter Type Default Description
section_uid str UUID string of the section containing the field — obtain from get_form_summary. Example: "3c3b0847-56fb-493f-bb84-2554b502a31e".
field_uid str UUID string of the field to update — obtain from get_form_summary or search_fields.
patch dict RFC 7396 merge-patch dict with fields to update. Voice/LLM keys (FEAT-649): hint (string or {locale: text}; "" clears it) and llm_validation (true/false; null inherits the form default).

Returns: dict — Success dict with updated field data, or error dict on failure.

Method EditToolkit.add_field

Add a new field to a section at an optional position.

field may carry a client-supplied field_uid (upsert origin); when omitted, a fresh one is minted automatically (FEAT-393) and returned in the result.

add_field(section_uid: str, field: dict, position: int | None = None) -> dict

Parameter Type Default Description
section_uid str UUID string of the section to add the field to — obtain from get_form_summary.
field dict Dict representation of the FormField to add.
position int | None None Optional 0-based insertion index. Appends if None.

Returns: dict — Success dict with the added field's field_uid/field_id, or error dict on failure.

Method EditToolkit.add_field_from_schema

Add a field from a raw schema dict with shortcut expansion.

Delegates to FormAssembler.assemble_field() (FEAT-388, Module 1) to expand convenience shortcuts (auto-generated field_id from label, string field_type coercion) before validating and applying the mutation via the existing add_field().

add_field_from_schema(section_uid: str, field_schema: dict, position: int | None = None) -> dict

Parameter Type Default Description
section_uid str UUID string of the section to add the field to — obtain from get_form_summary.
field_schema dict Dict with field definition (supports shortcuts: auto-generated field_id from label, string field_type).
position int | None None Optional 0-based insertion index. Appends if None.

Returns: dict — Success dict with added field's field_uid/field_id, or error dict on failure.

Method EditToolkit.remove_field

Remove a field from a section, addressed by UID.

remove_field(section_uid: str, field_uid: str) -> dict

Parameter Type Default Description
section_uid str UUID string of the section containing the field — obtain from get_form_summary.
field_uid str UUID string of the field to remove — obtain from get_form_summary or search_fields.

Returns: dict — Success dict, or error dict on failure.

Method EditToolkit.add_dependency

Set or replace the depends_on rule on a field.

Validates the rule dict via :class:DependencyRule and runs the form-level rule-integrity pass before applying. Returns an error dict (form unchanged) if validation fails.

rule's conditions/operations may reference other fields by their authored field_id (LLM ergonomics) — after applying, the form is routed through core.resolution.resolve_rule_references (FEAT-393) so the stored rule is UID-addressed before the integrity check runs.

add_dependency(field_uid: str, rule: dict) -> dict

Parameter Type Default Description
field_uid str UUID string of the field to update — obtain from get_form_summary or search_fields.
rule dict Dict representation of a :class:DependencyRule — field references inside conditions/operations use authored field_id strings.

Returns: dict — Success dict with the updated depends_on (UID-resolved), or an error dict.

Method EditToolkit.update_dependency

Merge-patch the existing depends_on rule on a field.

The patch is merged into the current rule dict. If the field has no existing rule, patch is used as the full new rule.

update_dependency(field_uid: str, patch: dict) -> dict

Parameter Type Default Description
field_uid str UUID string of the field to update — obtain from get_form_summary or search_fields.
patch dict Partial dict to merge into the existing DependencyRule.

Returns: dict — Success dict with the updated depends_on, or an error dict.

Method EditToolkit.remove_dependency

Clear the depends_on rule from a field.

remove_dependency(field_uid: str) -> dict

Parameter Type Default Description
field_uid str UUID string of the field to clear — obtain from get_form_summary or search_fields.

Returns: dict — Success dict, or error dict if the field is not found.

Method EditToolkit.add_post_dependency

Append a :class:PostDependency to a field's post_depends list.

Validates the post-dependency dict and runs rule-integrity before applying. Returns an error dict (form unchanged) if validation fails.

post's target/conditions/operation may reference other fields by their authored field_id (LLM ergonomics) — after applying, the form is routed through core.resolution. resolve_rule_references (FEAT-393) so stored references are UID-addressed before the integrity check runs.

add_post_dependency(field_uid: str, post: dict) -> dict

Parameter Type Default Description
field_uid str UUID string of the field to update — obtain from get_form_summary or search_fields.
post dict Dict representation of a :class:PostDependency — field references use authored field_id strings.

Returns: dict — Success dict with the full updated post_depends list (UID-resolved), or an error dict.

Method EditToolkit.remove_post_dependency

Remove a specific post-dependency (by target field_uid) from a field.

remove_post_dependency(field_uid: str, target: str) -> dict

Parameter Type Default Description
field_uid str UUID string of the owning field — obtain from get_form_summary or search_fields.
target str UUID string — the resolved target field_uid of the PostDependency to remove (as stored after resolve_rule_references has run, e.g. via add_post_dependency).

Returns: dict — Success dict with the remaining post_depends list, or an error dict.

Method EditToolkit.add_section

Add a new section to the form at an optional position.

add_section(section: dict, position: int | None = None) -> dict

Parameter Type Default Description
section dict Dict representation of the FormSection to add.
position int | None None Optional 0-based insertion index. Appends if None.

Returns: dict — Success dict with added section_id, or error dict on failure.

Method EditToolkit.add_section_from_schema

Add a section from a raw schema dict with shortcut expansion.

Delegates to FormAssembler.assemble_section() (FEAT-388, Module 1) to expand convenience shortcuts (auto-generated section_id, per-field shortcuts) before validating and applying the mutation via the existing add_section().

add_section_from_schema(section_schema: dict, position: int | None = None) -> dict

Parameter Type Default Description
section_schema dict Dict with section definition (supports shortcuts: auto-generated section_id, field shortcuts).
position int | None None Optional 0-based insertion index. Appends if None.

Returns: dict — Success dict with added section_id, or error dict on failure.

Method EditToolkit.update_section

Apply an RFC 7396 merge-patch to a section's meta dict.

This tool updates only the arbitrary meta key-value store on the section (section.meta). It does NOT update section.title. Use update_section_title to rename a section.

update_section(section_id: str, patch: dict) -> dict

Parameter Type Default Description
section_id str ID of the section to update.
patch dict Dict of key-value pairs to merge into section.meta.

Returns: dict — Success dict, or error dict on failure.

Method EditToolkit.move_field

Move a field within or across sections, addressed by UID.

move_field(from_section_uid: str, field_uid: str, to_section_uid: str, position: int | None = None) -> dict

Parameter Type Default Description
from_section_uid str UUID string of the source section — obtain from get_form_summary.
field_uid str UUID string of the field to move — obtain from get_form_summary or search_fields.
to_section_uid str UUID string of the destination section.
position int | None None Optional 0-based insertion index in the destination section.

Returns: dict — Success dict, or error dict on failure.

Method EditToolkit.update_form_meta

Apply an RFC 7396 merge-patch to the form-level meta dict.

This tool updates only the arbitrary meta key-value store on the form (form.meta). It does NOT update form.title or form.description. Use update_form_title to rename the form, or update_form_description to change the description.

update_form_meta(patch: dict) -> dict

Parameter Type Default Description
patch dict Dict of key-value pairs to merge into form.meta.

Returns: dict — Success dict, or error dict on failure.

Method EditToolkit.update_form_title

Update the form title.

Use this tool when the user asks to rename the form or change its title. This is the correct tool for changing form.title — do NOT use update_form_meta for this purpose.

update_form_title(title: str) -> dict

Parameter Type Default Description
title str New title for the form.

Returns: dict — Success dict confirming the title was updated, or error dict on failure.

Method EditToolkit.update_form_description

Update the form description.

Use this tool when the user asks to change or clear the form description. This is the correct tool for changing form.description — do NOT use update_form_meta for this purpose.

update_form_description(description: str | None) -> dict

Parameter Type Default Description
description str | None New description for the form. Pass null to clear it.

Returns: dict — Success dict confirming the description was updated, or error dict on failure.

Method EditToolkit.update_section_title

Update a section's title (rename a section).

Use this tool when the user asks to rename a section. This is the correct tool for changing section.title — do NOT use update_section (which only touches section.meta) for this purpose.

update_section_title(section_id: str, title: str) -> dict

Parameter Type Default Description
section_id str ID of the section to rename.
title str New title for the section.

Returns: dict — Success dict, or error dict if the section is not found.

Method EditToolkit.propose_voice_hints

Propose spoken hints/prompts for voice mode WITHOUT changing the form.

Returns proposals the author may apply later with update_field.

propose_voice_hints(form_uid: str, *, locale: str = 'en', fields: list[str] | None = None, style: str = 'concise', max_hint_words: int = 20) -> dict

Parameter Type Default Description
form_uid str UUID string of the form being edited (must match the working form).
locale str 'en' Locale of the proposed hints.
fields list[str] | None None Optional field_ids to restrict proposals to.
style str 'concise' Hint style, e.g. "concise".
max_hint_words int 20 Soft limit per hint (longer ones carry a warning).

Returns: dict — {"proposals": [...], "narration_preview": {...}} or an error dict.

Method EditToolkit.done

Signal that all edits are complete.

After calling this tool the LLM should stop making further tool calls. The caller retrieves the final updated form via the form property.

done() -> dict

Returns: dict — Success dict confirming edits are complete.

Method EditToolkit.get_tool_definitions

Return the list of AbstractTool instances for all 12 toolkit tools.

Delegates to get_tools() which is the canonical AbstractToolkit method for retrieving tool instances. GoogleGenAIClient.ask() accepts the result directly as the tools= argument.

get_tool_definitions() -> list

Returns: list — List of AbstractTool instances (ToolkitTool wrappers).

Method EditToolkit.execute_tool

Execute a toolkit tool by name.

Looks up the tool in the toolkit's tool cache and invokes it with the given arguments.

execute_tool(tool_name: str, arguments: dict) -> dict

Parameter Type Default Description
tool_name str Name of the tool to invoke (e.g. "get_field").
arguments dict Dict of arguments to pass to the tool.

Returns: dict — Tool result dict.

Alias FormAssembler

Re-exported from parrot_formdesigner.assembler.FormAssembler.

Alias FormField

Re-exported from parrot_formdesigner.core.schema.FormField.

Alias FormSchema

Re-exported from parrot_formdesigner.core.schema.FormSchema.

Alias FormSection

Re-exported from parrot_formdesigner.core.schema.FormSection.

Alias FormSubsection

Re-exported from parrot_formdesigner.core.schema.FormSubsection.

Alias MoveField

Re-exported from parrot_formdesigner.api.operations.MoveField.

Alias OperationError

Re-exported from parrot_formdesigner.api.operations.OperationError.

Alias PostDependency

Re-exported from parrot_formdesigner.core.constraints.PostDependency.

Alias RemoveField

Re-exported from parrot_formdesigner.api.operations.RemoveField.

Alias UpdateField

Re-exported from parrot_formdesigner.api.operations.UpdateField.

Alias UpdateFormMeta

Re-exported from parrot_formdesigner.api.operations.UpdateFormMeta.

Alias UpdateSectionMeta

Re-exported from parrot_formdesigner.api.operations.UpdateSectionMeta.

Alias find_field_by_uid

Re-exported from parrot_formdesigner.core.resolution.find_field_by_uid.

Alias resolve_rule_references

Re-exported from parrot_formdesigner.core.resolution.resolve_rule_references.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally