Day 7 โ€“ Edit & Revalidate AI-Extracted Fields #LaravelGPT #AIValidation #SmartDocs #DocumentReview #AIWorkflow #LaravelAI


Today weโ€™ll enable users to edit GPT-extracted fields and then revalidate them using GPT โ€” closing the loop on AI-assisted document correction and verification.


๐ŸŽฏ Goal

Allow admins or reviewers to update any incorrect AI-extracted field and click a button to ask GPT to recheck based on the modified data.


โœ๏ธ Step 1: Allow Field Editing

Ensure the editable form from Day 4 exists in show.blade.php:

<form method="POST" action="{{ route('documents.updateFields', $document->id) }}">
    @csrf
    @method('PUT')
    @foreach(json_decode($document->extracted_fields, true) as $key => $value)
        <label>{{ ucfirst(str_replace('_', ' ', $key)) }}</label>
        <input type="text" name="fields[{{ $key }}]" value="{{ $value }}">
    @endforeach
    <button type="submit" class="btn btn-primary mt-2">Save Changes</button>
</form>

๐Ÿ” Step 2: Add Revalidate Button

Below the field form:

<form method="POST" action="{{ route('documents.revalidate', $document->id) }}">
    @csrf
    <button type="submit" class="btn btn-warning mt-2">Revalidate with GPT</button>
</form>

๐Ÿ” Step 3: Add Route & Controller Logic

In web.php:

Route::post('/documents/{document}/revalidate', [DocumentController::class, 'revalidate'])->name('documents.revalidate');

In DocumentController.php:

public function revalidate(Document $document, DocumentAnalysisService $ai)
{
    $fields = json_decode($document->extracted_fields, true);
    $notes = $ai->validateDocument($document->extracted_text, $fields);

    $status = 'validated';
    if (str_contains($notes, 'missing') || str_contains($notes, 'inconsistenc')) {
        $status = 'warning';
    }
    if (str_contains($notes, 'risky') || str_contains($notes, 'termination')) {
        $status = 'error';
    }

    $document->update([
        'validation_notes' => $notes,
        'validation_status' => $status,
    ]);

    return back()->with('success', 'Document revalidated.');
}

โœ… Summary

โœ… Today you:

  • Enabled editing of AI-extracted fields
  • Built a revalidation loop using GPT
  • Updated trust status based on latest review

โœ… Up next (Day 8): Weโ€™ll export validated data into structured formats like JSON or CSV, enabling API responses or integrations with other systems.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.