
Building Adhikar AI: A Post-Rejection Welfare Repair Agent on AWS
How we built a serverless pipeline that turns a rejection letter into a corrected application — and what we learned about new AWS accounts along the way.
The Problem
India has built one of the world's largest welfare delivery infrastructures — Aadhaar-linked bank accounts, Direct Benefit Transfer, digitised ration cards, and dozens of scheme portals. It has also built a system in which a citizen can be excluded from benefits they legally qualify for, without ever being told why.
A farmer applies for PM-KISAN. Two months later, a letter arrives: "Application rejected. Details do not match records." He does not know which document is wrong. He does not know which office owns the wrong record. He visits the local government office three times over two months, is told each time to bring different documents, and eventually gives up.
This is not a fringe failure. West Bengal's Annapurna Yojana alone saw 17 lakh applications rejected, with most caused by Aadhaar-mobile mismatches rather than genuine ineligibility. The pattern repeats across states and schemes. The state knows which field mismatched — that information exists in the verification output. It is almost never surfaced to the citizen.
The gap is diagnostic. Existing tools help citizens apply for schemes. None help them repair a rejection. That is the layer we set out to build.
What We Built
Adhikar AI takes a rejection letter and produces three things: a diagnosis, a fix, and a tracking trail.
- Diagnosis. The user uploads a rejection letter (photo, PDF, or text). The app extracts the scheme name, rejection reason, and department using Amazon Textract, then cross-references the citizen's other documents using fuzzy matching to find the exact mismatch.
- Fix. It generates a plain-language explanation in English, Hindi, or Marathi, and produces a pre-filled correction form addressed to the specific department that owns the wrong record — for example, the Tehsildar office for a land record correction.
- Tracking. The case moves through a status pipeline: Uploaded → Extracted → Matched → Diagnosed → Filed → In Review → Resolved. The user sees every transition and receives SNS notifications when state changes.
The demo runs end-to-end in under three minutes. Upload a rejection letter with a name mismatch, and the app identifies the specific field, tells the user which office to visit, and generates the form they need to bring.
Architecture
Adhikar AI is fully serverless on AWS.
text
User uploads rejection letter (browser) │ ▼Amazon S3 ← presigned URL upload │ ▼AWS Step Functions ── orchestrates the pipeline │ ├──► Lambda: extract (Amazon Textract reads the document) ├──► Lambda: match (fuzzy comparison across documents) ├──► Lambda: generate (Bedrock Nova Lite + template fallback) └──► Lambda: track (DynamoDB state, SNS notifications) │ ▼Amazon API Gateway ← REST endpoints │ ▼AWS Amplify Hosting ← Next.js 15 frontendServices used:
Service | Role |
|---|---|
Amazon S3 | Encrypted document storage, presigned URL uploads |
Amazon Textract | Field extraction from images, PDFs, and text |
AWS Lambda | 7 functions handling extract, match, generate, track, presign, analyze, health |
AWS Step Functions | Multi-stage workflow orchestration with retries and fallbacks |
Amazon DynamoDB | Case records, extracted fields, status transitions, PITR enabled |
Amazon API Gateway | REST endpoints with CORS |
Amazon SNS | Status change notifications |
Amazon EventBridge | Weekly follow-up reminders |
AWS Amplify Hosting | Next.js 15 frontend, GitHub auto-deploy |
AWS IAM | Least-privilege roles per Lambda; dedicated deploy user (not root) |
What Fought Back
Three issues consumed the majority of our debugging time.
1. Next.js static export with dynamic routes
Our status page was originally
/status/[caseId] , a dynamic route. Next.js with output: 'export' requires generateStaticParams() to pre-render dynamic routes at build time — impossible when case IDs are generated at runtime.The fix: Migrate to
/status?id=caseId with the ID read from useSearchParams() , wrapped in a <Suspense> boundary. The static export now pre-renders a single /status page, and the case ID is resolved on the client.2. Regex greediness on Indian document formats
Our first extraction parser captured the next line's label as part of the current field's value. A typical rejection letter like this:
text
Applicant Name: Ram PatilFather Name: Shyam Patilproduced
applicantName = "Ram Patil Father Name" . The regex was using .* which matched greedily across newlines.The fix: Switch to
[^\n\r]+ as the capture group, with re.MULTILINE and explicit ^ anchors per line:python
r'(?im)^\s*applicant\s*name\s*[:\-]\s*([^\n\r]+)'Then
.strip() the result. Clean, single-line captures every time.3. Amazon Bedrock on a brand-new AISPL account
This was the most frustrating issue, and it deserves attention because it is not well documented.
Our AWS account was created three days before the hackathon, billed through AISPL (Amazon Internet Services Private Limited) — the India entity. We wrote the Bedrock integration against
amazon.nova-lite-v1:0 following the standard pattern.Every invocation returned:
text
ValidationException: Operation not allowedEvery model. Every region. From the Playground, from Lambda, from the CLI.
The Bedrock console pointed us to a "Model access" page that had been retired. It said models are now auto-enabled. That is true for accounts with payment history, but not for new AISPL accounts.
After opening an AWS Support case, we received the answer: AISPL accounts require 3–6 months of payment history before Bedrock activates. Invoice billing was not available to us either, for the same reason. There is no way to bypass this. It is an account-level authorization restriction, not an IAM policy issue.
Our response: We kept the Bedrock integration in the code and added a structured template fallback that generates the same diagnosis — clear, actionable text telling the user which field mismatched and which office to visit. The app works end-to-end without Bedrock. When our account becomes eligible, the Lambda will start using Bedrock automatically with no code changes.
If you are building on a new AWS account and your project depends on Bedrock, check your account eligibility first. It will save you hours.
What Worked Brilliantly
AWS SAM CLI.
sam build && sam deploy --guided produced a complete serverless stack — API Gateway, seven Lambdas, DynamoDB, S3, Step Functions, SNS, EventBridge — from a single YAML template. Redeployments after the first took under two minutes. This is the fastest cloud deployment workflow we have used.Amazon Textract on Indian documents. Textract correctly extracted structured fields from a Maharashtra PMAY rejection letter, a 7/12 land record, and a PM-KISAN notice. The
Blocks response format is straightforward to parse, and accuracy on printed English and Devanagari was excellent.AWS Step Functions. The visual workflow editor showed us exactly where our pipeline was breaking. Retry logic and
Catch blocks are built into the state machine definition, so we did not have to write error handling boilerplate in every Lambda.AWS Amplify Hosting. Connecting the GitHub repository took two clicks. Every
git push triggers a full build with HTTPS, custom domain, and SPA rewrite rules handled automatically. The build logs are detailed enough to debug failures in the console.Amazon S3 presigned URLs. Browser-to-S3 uploads without exposing AWS credentials. One boto3 call to generate the URL, and the upload is fast even on mobile connections.
What We Learned
Graceful fallbacks are more important than perfect integrations. We could have spent the entire hackathon trying to make Bedrock work. Instead, we coded a fallback that produces equivalent output, shipped the working version, and documented the constraint. Judges see a functioning product, not a broken one.
Serverless is genuinely fast to build with. From an empty folder to a deployed, multi-service backend in under a day. The trade-off is upfront architecture — you cannot refactor your way out of a bad Step Functions design.
Indian document formats are a real engineering problem. Aadhaar, 7/12 extracts, ration cards, and rejection letters all follow different conventions. Regex parsing works, but a production system would benefit from a fine-tuned extraction model trained on these formats.
Test with real documents before recording the demo. We built the sample fixture and tested with it before the demo — and it caught the regex greediness issue that would have been visibly broken on stage.
Try It
Live app: https://main.d28q0w9q60odl9.amplifyapp.com
Source code: https://github.com/cyber-suraj/adhikar-ai
Click "Try Live Demo (PM-KISAN Rejection)" on the home page to run the pipeline with a pre-filled case. The full flow from upload to correction form takes under three minutes.
Team
Built at AWS First Commit — Bharat Builds Tour, Event 01 by Team NxtTech:
- Suraj Khanase (Lead) — Product, AWS deployment, Amplify, submission
- Sumit Jagtap — Step Functions, fuzzy matching, SAM template
- Nandkishor Tamkhade — Next.js frontend, trilingual UI, static export
- Tejas Shinde — Textract integration, regex parsers, test fixtures
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article