Inferensys

Prompt

Form Field Dependency Graph Prompt

A practical prompt playbook for using the Form Field Dependency Graph Prompt in production AI workflows to map conditional logic between fields.
Operations team reviewing AI workflow automation on laptop, workflow builder visible, casual office setup.
PROMPT PLAYBOOK

When to Use This Prompt

Determine if the Form Field Dependency Graph Prompt is the right tool for mapping conditional logic from static form documents into a machine-readable dependency structure.

This prompt is designed for form automation engineers who need to extract and codify the conditional logic embedded in static form documents. The primary job-to-be-done is converting a human-readable form (PDF, paper scan, or static HTML) into a dynamic, interactive digital experience. The ideal user has already completed field-level extraction—identifying labels, types, bounding boxes, and positions for every field on the form—and has also isolated the form's instructional text. This prompt does not perform OCR, field detection, or label association; it assumes those upstream tasks are complete and focuses exclusively on the relationships between fields.

Use this prompt when you need to map three specific dependency types: show/hide (conditional visibility of fields or sections), enable/disable (conditional editability), and populate/validate (auto-fill rules and cross-field validation constraints). The prompt analyzes both explicit dependencies stated in form instructions (e.g., 'If yes to Question 4, complete Section B') and implicit dependencies inferred from layout proximity and grouping (e.g., a set of address fields that appear only when a 'mailing address differs' checkbox is selected). The output is a structured dependency graph where each node is a field and each edge defines a trigger condition, an action, and the affected target fields.

Do not use this prompt when the form logic is already expressed in a machine-readable format like JSON Schema conditionals, XFA, or a dynamic form builder's internal representation. It is also unsuitable for forms where conditional logic is purely sequential (every field depends only on the previous field) without branching, as simpler rule-based parsers will be more reliable. Avoid this prompt when the form instructions are contradictory, heavily redacted, or written in a language the model cannot reliably parse. For high-stakes workflows—such as legal filings, insurance claims, or healthcare intake—always route the generated dependency graph through a human review step before wiring it into a production form renderer, as a missed dependency can cause users to skip required fields or expose irrelevant sections.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Form Field Dependency Graph Prompt delivers reliable automation and where it introduces unacceptable risk. Use these cards to decide if this prompt fits your pipeline before investing in integration.

01

Good Fit: Structured Forms with Explicit Rules

Use when: Forms contain written instructions like 'If Yes, skip to Section 4' or 'Complete only if employed.' The prompt excels at extracting explicit conditional logic from text instructions and mapping it to field identifiers. Guardrail: Always validate extracted rules against a known rule schema before ingesting into your form engine.

02

Good Fit: Multi-Page Forms with Cross-References

Use when: Forms span pages and contain instructions like 'See Page 3' or 'Refer to Schedule A.' The prompt is designed to track dependencies across page boundaries. Guardrail: Run the multi-page field tracking prompt first to establish page-span identifiers, then feed those into the dependency graph prompt to avoid broken references.

03

Bad Fit: Purely Visual or Icon-Based Dependencies

Avoid when: Forms rely on color coding, icons, or spatial grouping without text instructions to indicate conditional logic. The prompt reasons from language, not visual design patterns. Guardrail: Pair with a layout-aware extraction prompt to capture visual grouping, then merge outputs in application logic rather than expecting the dependency prompt to infer visual rules.

04

Bad Fit: Dynamic Forms with Client-Side Logic Only

Avoid when: Conditional logic exists only in JavaScript or client-side code with no textual representation in the form document itself. The prompt cannot reverse-engineer code behavior from a static PDF. Guardrail: Use this prompt only on the form's textual specification or instructions layer. For code-driven forms, extract rules from the application source, not the rendered document.

05

Required Inputs: Field Inventory with Identifiers

Risk: Without a complete field list with stable identifiers, the prompt produces dependency references that cannot be resolved. Guardrail: Run a field extraction prompt first to produce a field inventory with unique IDs, labels, types, and page locations. Feed that inventory as [FIELD_INVENTORY] into the dependency graph prompt so all references are traceable.

06

Operational Risk: False Dependencies from Coincidental Layout

Risk: The prompt may infer a dependency between two fields simply because they appear near each other, even when no logical relationship exists. This produces spurious show/hide rules that break form behavior. Guardrail: Require the prompt to cite specific textual evidence for every dependency edge. Flag edges based solely on proximity for human review before ingestion.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A production-ready prompt template that maps conditional logic between form fields and outputs a structured dependency graph.

This prompt template is designed to be copied directly into your prompt management system or codebase. It instructs the model to analyze a form's field inventory and associated instructions to produce a dependency graph in strict JSON. The graph captures relationships such as show/hide, enable/disable, populate, and validate, along with the trigger conditions and affected fields. The template uses square-bracket placeholders for all dynamic inputs, making it safe to embed in Python f-strings, Jinja2 templates, or any string-substitution system without conflicting with the model's own tokenization.

text
You are an expert form automation engineer. Your task is to analyze the provided form field inventory and form instructions to produce a dependency graph. The graph must capture all conditional logic between fields, including show/hide, enable/disable, auto-populate, and cross-field validation rules.

## INPUT
- **Form Field Inventory:** [FIELD_INVENTORY]
- **Form Instructions:** [FORM_INSTRUCTIONS]
- **Document Layout Context (optional):** [LAYOUT_CONTEXT]

## OUTPUT SCHEMA
Return ONLY a valid JSON object with this structure:
{
  "dependencies": [
    {
      "rule_id": "string",
      "rule_type": "show" | "hide" | "enable" | "disable" | "populate" | "validate",
      "trigger": {
        "field_id": "string",
        "condition": "equals" | "not_equals" | "contains" | "greater_than" | "less_than" | "is_filled" | "is_empty",
        "value": "string | null"
      },
      "target_field_ids": ["string"],
      "action_description": "string",
      "source": "explicit_instruction" | "layout_proximity" | "inferred",
      "confidence": 0.0-1.0
    }
  ],
  "unresolved_ambiguities": [
    {
      "field_ids": ["string"],
      "description": "string",
      "possible_interpretations": ["string"]
    }
  ]
}

## CONSTRAINTS
- Do not invent dependencies that are not supported by the instructions or layout context.
- Distinguish between explicit dependencies (stated in instructions) and implicit dependencies (inferred from layout proximity). Set the `source` field accordingly.
- For implicit dependencies, set `confidence` below 0.8 and include an entry in `unresolved_ambiguities`.
- Handle cross-page references: if a field on page 2 depends on a field on page 1, include the dependency and note the page span in `action_description`.
- Ignore coincidental layout proximity that does not imply a logical dependency.
- If the instructions are ambiguous, do not guess. Document the ambiguity in `unresolved_ambiguities`.

## EXAMPLES
[FEW_SHOT_EXAMPLES]

## RISK LEVEL
[RISK_LEVEL]

To adapt this template for your pipeline, replace each bracketed placeholder with data from your document processing system. [FIELD_INVENTORY] should be a structured list of fields extracted from the form, including field IDs, labels, types, and page locations. [FORM_INSTRUCTIONS] is the raw or preprocessed text of any instructions printed on the form itself. [LAYOUT_CONTEXT] is optional but recommended for complex multi-column forms; it should describe spatial relationships between fields. [FEW_SHOT_EXAMPLES] should contain 2-3 annotated examples of correct dependency graphs for forms similar to yours. [RISK_LEVEL] should be set to "high" if the form is used in a regulated domain (legal, healthcare, finance), which will cause the model to apply stricter confidence thresholds and flag more ambiguities for human review. After generating the graph, always validate the JSON structure against your schema before ingesting it into your form automation engine. For high-risk workflows, route any dependency with confidence below 0.9 or source equal to "inferred" to a human reviewer before activating the conditional logic in production.

IMPLEMENTATION TABLE

Prompt Variables

Placeholders required by the Form Field Dependency Graph Prompt. Replace each with concrete values before execution. Validation notes describe how to check inputs before they reach the model.

PlaceholderPurposeExampleValidation Notes

[FORM_FIELDS]

Array of field objects with id, label, type, page, and bounding box from upstream extraction

[{"id":"f1","label":"Applicant Name","type":"text","page":1,"bbox":[10,20,200,40]}]

Schema check: each object must have id, label, type, page, bbox. Type must be in allowed enum. Bbox must be four positive numbers. Empty array triggers abort.

[FORM_INSTRUCTIONS]

Full text of form instructions, help text, tooltips, and conditional logic statements extracted from the document

"Section 3: If 'Co-Applicant' is checked, complete fields 12-18. Otherwise skip to Section 4."

Null allowed when form has no explicit instructions. Empty string triggers dependency-from-layout-only mode. Must be plain text, not markdown.

[FIELD_PROXIMITY_THRESHOLD]

Pixel or normalized distance defining when adjacent fields are considered potentially dependent

50

Must be positive integer or float. Values below 10 may miss cross-column dependencies. Values above 200 may produce false dependencies from coincidental layout. Default 75 if not specified.

[CROSS_PAGE_CONTEXT]

Boolean flag enabling dependency detection across page boundaries

Must be true or false. When false, dependencies spanning pages are not detected. Set true for multi-page forms. Set false for single-page forms to reduce false positives.

[OUTPUT_SCHEMA]

JSON schema the dependency graph output must conform to

{"type":"object","properties":{"dependencies":{"type":"array"}},"required":["dependencies"]}

Must be valid JSON Schema draft-07 or later. Parse check before prompt assembly. Schema must include dependencies array with trigger_field, affected_field, condition, and dependency_type properties.

[CONFIDENCE_THRESHOLD]

Minimum confidence score for including a dependency in the output

0.7

Must be float between 0.0 and 1.0. Dependencies below threshold are omitted or flagged as low-confidence. Values below 0.5 increase false positives. Values above 0.9 may miss implicit layout-based dependencies.

[MAX_DEPENDENCIES]

Upper bound on number of dependencies returned to prevent runaway output on dense forms

200

Must be positive integer. Exceeding this count triggers truncation with warning. Set based on form complexity: 50 for simple forms, 200 for dense multi-page forms, 500 for very large form sets.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the dependency graph prompt into a production form processing pipeline with validation, retries, and human review.

The Form Field Dependency Graph Prompt is designed to be called after field extraction and label association are complete. The input should be a structured representation of all detected fields—including their labels, types, positions, and page numbers—along with any form instructions or instructional text extracted from the document. This prompt is not a standalone document reader; it requires pre-processed field data from upstream extraction steps. The output is a machine-readable dependency graph (JSON) that your application can consume to dynamically show, hide, enable, disable, populate, or validate fields in a form UI or processing workflow.

Wire this prompt into your pipeline as a post-extraction reasoning step. First, assemble the [FIELD_LIST] as a JSON array of objects, each containing field_id, label, type, page, bounding_box, and value_state (filled/empty). Include [FORM_INSTRUCTIONS] as raw text extracted from the document's instructional sections. Set [OUTPUT_SCHEMA] to require a JSON object with a dependencies array, where each dependency has trigger_field_id, condition (e.g., 'equals', 'is_filled', 'is_checked'), trigger_value, action (e.g., 'show', 'hide', 'enable', 'populate', 'validate'), affected_field_ids (array), and confidence (0-1). Implement a validation layer that checks: (1) all field_id references exist in the input field list, (2) no circular dependencies exist in the graph, (3) confidence values are present for every edge, and (4) cross-page references are explicitly flagged with a cross_page boolean. On validation failure, retry up to two times with the validation errors appended to [CONSTRAINTS]. If retries fail, route the document to a human review queue with the partial graph and error details attached.

For model selection, use a model with strong reasoning capabilities and long-context handling, such as GPT-4o, Claude 3.5 Sonnet, or Gemini 1.5 Pro. The prompt benefits from models that can reason about spatial layout when bounding box coordinates are provided. Set temperature to 0.1–0.2 for deterministic outputs. Log every invocation with the input field count, output dependency count, validation pass/fail status, retry count, and any human review escalations. This telemetry is critical for detecting drift in extraction quality upstream—if dependency confidence scores trend downward, investigate whether your field label association or OCR steps are introducing noise. Avoid running this prompt on documents with fewer than five fields; trivial forms rarely have meaningful dependencies and waste inference cost. For high-throughput pipelines, consider caching dependency graphs for standard form templates and only invoking the prompt when the form layout or instruction text differs from known templates.

IMPLEMENTATION TABLE

Expected Output Contract

Defines the structure, types, and validation rules for the dependency graph object returned by the Form Field Dependency Graph Prompt. Use this contract to parse, validate, and integrate the model's output into a form automation pipeline.

Field or ElementType or FormatRequiredValidation Rule

dependency_graph

object

Top-level object must contain a 'dependencies' array. Schema check: parse with JSON Schema validator.

dependencies

array

Must be a non-empty array. Each item must match the dependency object schema. If no dependencies are found, return an empty array.

dependency.source_field_id

string

Must match a field identifier from the [INPUT_FORM_SCHEMA]. Regex check against provided field IDs. Null not allowed.

dependency.target_field_id

string

Must match a field identifier from the [INPUT_FORM_SCHEMA]. Must not be the same as source_field_id. Null not allowed.

dependency.relationship_type

enum

Must be one of: 'show', 'hide', 'enable', 'disable', 'populate', 'validate'. Enum check against allowed values.

dependency.trigger_condition

string

A natural language description of the condition. Must be non-empty. Check for null or whitespace-only strings.

dependency.evidence_source

enum

Must be one of: 'explicit_instruction', 'layout_proximity', 'field_label', 'cross_reference'. Enum check against allowed values.

dependency.confidence

number

A float between 0.0 and 1.0. Confidence threshold check: flag for human review if < [CONFIDENCE_THRESHOLD].

PRACTICAL GUARDRAILS

Common Failure Modes

Dependency graph extraction fails silently in ways that corrupt downstream form logic. These are the most common failure patterns and how to guard against them before the graph reaches your form engine.

01

False Dependencies from Coincidental Layout

What to watch: The model infers a dependency between two fields simply because they are visually adjacent or aligned in the layout grid, even when no logical relationship exists. This is common in dense forms where unrelated fields share column alignment. Guardrail: Require the prompt to cite explicit evidence (form instructions, field labels, conditional language) for every dependency edge. Add a post-extraction validator that flags edges supported only by spatial proximity without textual evidence.

02

Missed Dependencies Across Page Breaks

What to watch: Conditional logic that references fields on a previous page is dropped when the model processes pages independently or loses context across page boundaries. Multi-page forms with carryover conditions are especially vulnerable. Guardrail: Structure the prompt to process the entire document as a single context window when possible. Add a cross-page reconciliation step that checks for dangling references (fields mentioned in conditions but not present in the current page's output) and re-scans previous pages.

03

Implicit Dependency Misclassification

What to watch: The model conflates different dependency types—treating a visibility rule (show/hide) as a validation rule, or a populate action as an enable/disable condition. This causes incorrect behavior when the graph is executed by a form engine. Guardrail: Use a strict enum for dependency types in the output schema (show, hide, enable, disable, populate, validate, require) and include a self-check instruction that asks the model to verify each edge's type against the original form language before emitting.

04

Trigger Condition Ambiguity

What to watch: The model extracts a dependency but produces a vague or incorrect trigger condition—for example, 'when Field A is filled' instead of the actual condition 'when Field A equals Yes.' This causes the dependency to fire at the wrong time. Guardrail: Require the prompt to extract the exact trigger value or expression from the form text, not paraphrase it. Add a validator that rejects trigger conditions using generic predicates like 'is filled' or 'is present' unless those are the literal form instructions.

05

Orphaned Affected Fields

What to watch: A dependency edge references an affected field that doesn't exist in the extracted field list—either because the field was missed during extraction or because the model hallucinated a field name. Guardrail: Post-process the dependency graph against the extracted field inventory. Flag any edge where the source or target field ID is not present in the field list. Route orphaned edges to a human review queue with the surrounding document context for resolution.

06

Circular Dependency Introduction

What to watch: The model creates circular dependencies (Field A depends on Field B, which depends on Field A) that don't exist in the actual form logic, usually by misreading reciprocal conditions or bidirectional validation rules. Guardrail: Run a cycle detection algorithm on the output graph before ingestion. If cycles are found, re-prompt the model with the specific cycle identified and ask it to re-examine the form text for the correct directional relationship, or flag for human review if the cycle is genuine.

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to test the Form Field Dependency Graph Prompt before deploying it into a production form automation pipeline. Each criterion targets a known failure mode for dependency extraction from complex documents.

CriterionPass StandardFailure SignalTest Method

Explicit Dependency Extraction

All dependencies stated in form instructions (e.g., 'If [FIELD_A] is Yes, complete [FIELD_B]') appear in the output graph with correct trigger condition and affected field.

Missing documented dependency; trigger condition inverted; affected field references a non-existent field.

Run prompt against a form with 5+ documented conditional rules. Diff output dependencies against a manually curated ground-truth list from the instructions text.

Implicit Dependency Detection

Dependencies inferred from layout proximity (adjacent fields, grouped sections) are present and marked with source 'layout_proximity'. No more than 1 false implicit dependency per 10 fields.

High false-positive rate on coincidental adjacency; missed true implicit dependencies from visually grouped but non-adjacent fields.

Use a form with known implicit dependencies (e.g., address block where ZIP depends on State). Verify each implicit edge against a human-annotated reference. Count false positives on a form with random field placement.

Cross-Page Dependency Tracking

Dependencies that span page breaks (e.g., 'See Section 3 on page 2') are correctly resolved with the target field identified on the referenced page.

Broken reference with null target field; target field mapped to wrong page; dependency dropped entirely when source and target are on different pages.

Feed a multi-page form with at least 2 explicit cross-page dependencies. Check that each cross-page edge has a non-null target field ID and correct page number.

False Dependency Rejection

No dependency edges are created between fields that are merely coincidentally aligned in layout but have no logical relationship.

Spurious edges between unrelated fields in the same row or column; false dependencies from shared formatting (e.g., all bold labels treated as a group).

Run prompt on a dense form with grid layout but no conditional logic. Output should have zero or near-zero dependency edges. Count any edge as a failure unless it can be justified from explicit instructions.

Dependency Type Classification

Each edge is classified into exactly one of: show/hide, enable/disable, populate, validate. Classification matches the form's intended behavior.

Populate classified as validate; enable/disable classified as show/hide; multiple types assigned to a single edge without clear evidence.

Use a form with one example of each dependency type. Verify type labels against a pre-labeled test set. Require 100% accuracy on type classification for explicit dependencies.

Trigger Condition Accuracy

Trigger conditions include the operator (equals, not_equals, contains, greater_than, is_filled) and the threshold value when applicable.

Missing operator; vague condition like 'if field has value'; threshold value omitted for comparison operators; condition references a value not present in the form.

Extract trigger conditions from 10 dependencies. Parse each condition string and verify it contains a valid operator and value. Flag any condition that cannot be evaluated programmatically.

Output Schema Compliance

Output is valid JSON matching the expected schema with all required fields (source_field_id, target_field_id, dependency_type, trigger_condition, evidence_source) present and correctly typed.

Missing required fields; wrong types (e.g., evidence_source as object instead of string); extra fields that violate schema; malformed JSON.

Validate output with a JSON Schema validator. Run against 5 different forms. Require 100% schema compliance across all runs.

Evidence Grounding

Every dependency edge includes an evidence_source field that cites either the instruction text (with quote), layout observation (with bounding box reference), or both.

Null or empty evidence_source; vague citation like 'from the form'; evidence that does not support the claimed dependency when manually reviewed.

Sample 10 dependency edges from output. For each, locate the cited evidence in the source document. Require that 9/10 citations are verifiable and support the dependency claim.

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Start with the base prompt and a single-page form. Remove strict output schema requirements and accept free-text dependency descriptions. Use a smaller context window and test with 3-5 fields before scaling.

code
Analyze this form and describe which fields depend on each other.

Form fields: [FIELD_LIST]
Form instructions: [INSTRUCTIONS]

Describe dependencies in plain language.

Watch for

  • Missed implicit dependencies from layout proximity
  • Over-reporting coincidental alignment as dependencies
  • No confidence scoring on uncertain relationships
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.