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.