Skip to content

feat(ai-service): implement humanitarian verification prompt engine with Sphere criteria and fallback flow#228

Merged
Cedarich merged 2 commits intoPulsefy:mainfrom
rachealkenny:feature/Automated-Prompt-Engineering-for-Humanitarian-Verification
Mar 29, 2026
Merged

feat(ai-service): implement humanitarian verification prompt engine with Sphere criteria and fallback flow#228
Cedarich merged 2 commits intoPulsefy:mainfrom
rachealkenny:feature/Automated-Prompt-Engineering-for-Humanitarian-Verification

Conversation

@rachealkenny
Copy link
Copy Markdown
Contributor

Summary

Implements a standardized humanitarian verification prompt engine for LLMs (OpenAI/Grok) that integrates Sphere Handbook criteria, supports backend-driven context factors, and provides resilient fallback behavior across providers.

Changes

  • Adds Python prompt template engine with primary and fallback prompts
  • Integrates Sphere Handbook criteria into verification prompts for objective aid‑claim assessment
  • Allows NestJS backend to pass context_factors to influence prompt construction
  • Implements fallback flow across prompt variants and providers (OpenAI → Groq) with structured error capture
  • Adds humanitarian verification API contracts, endpoint wiring, and Celery task integration
  • Extends configuration with model/timeout settings, environment examples, and README documentation
  • Includes tests for prompt rendering, context inclusion, fallback execution, endpoint behavior, and OCR stability

Validation

  • All 63 tests passed locally
  • Verified prompt rendering with and without context factors
  • Confirmed fallback execution on primary model failure

Closes #159

…ith Sphere criteria and fallback flow

Adds a standardized Humanitarian Standard prompt template engine for LLM verification workflows.

Integrates Sphere Handbook criteria into primary verification prompts to improve consistency and objectivity of aid-claim assessment.

Introduces backend-driven context_factors support so NestJS can pass operational context that influences prompt construction and evaluation framing.

Implements resilient fallback behavior across prompt variants (primary to fallback) and configured providers (OpenAI and Groq) with structured error capture.

Adds humanitarian verification API contracts and endpoint wiring, plus Celery task integration for asynchronous processing.

Extends configuration with model/timeout settings and updates environment examples and README documentation.

Includes test coverage for prompt rendering, context-factor inclusion, fallback execution path, endpoint success/failure behavior, and environment-stable OCR testing.

Validation: full test suite passed locally (63 passed).
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 29, 2026

@rachealkenny Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@rachealkenny
Copy link
Copy Markdown
Contributor Author

@Cedarich done.

@Cedarich
Copy link
Copy Markdown
Contributor

Please help star our repo

Initialize Celery app lazily on first use instead of at module import time.
This allows the AI service to start and serve requests (including health checks)
even when Redis is unavailable, fixing the Docker CI health check failure.

Benefits:
- Docker health checks pass during CI testing without Redis
- Production functionality unchanged when Redis is available
- Graceful degradation - tasks fail with clear error messages when Redis missing
- All existing callers work identically

Changes:
- Wrapped Celery initialization in get_celery_app() function
- Task decorator deferred via get_process_heavy_inference_task()
- create_task() now handles missing Redis gracefully
- Dummy Celery app created as fallback to prevent crashes

Fixes: CI failure 'curl: (7) Failed to connect to localhost port 8000'
@Cedarich Cedarich merged commit 35378e7 into Pulsefy:main Mar 29, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automated Prompt Engineering for Humanitarian Verification

2 participants