Build a Logistics Cargo Declaration FormSG Webhook Processor — implementation
Linked challenge: Build a Logistics Cargo Declaration FormSG Webhook Processor
Prompt source
implementation74 lines11 sectionsNo variables1 code block
## Build
Process incoming cargo declaration webhooks from FormSG. Verify webhook authenticity, classify cargo descriptions into standardized HS codes using an LLM, and calculate initial port handling fees.
## User
Freight forwarding operations agent
## Workflow
1. Ingest incoming webhook payloads representing cargo declaration forms submitted via FormSG.
2. Authenticate the payload by verifying the mock FormSG webhook signature to ensure data origin authenticity.
3. Analyze the cargo description field with an LLM to predict the most likely 6-digit HS commodity code.
4. Calculate port handling fees based on the submitted weight (0.50 SGD per kg for standard cargo, 0.70 SGD per kg for hazardous cargo), generating a billing draft.
## Interface
Freight operations dashboard showing verified FormSG submissions, predicted HS codes, and calculated handling fee estimates.
## Data
Synthetic JSON array of 20 simplified synthetic app records (not complete official schema files) representing mock FormSG webhook payloads containing cargo descriptions and weights.
Starter examples below are synthetic. They are not downloaded records.
## Source
[Singapore government FormSG](https://raw.githubusercontent.com/opengovsg/FormSG/develop/README.md)
Utilizes the FormSG webhook verification concepts to authenticate incoming cargo declarations before processing.
## Tools
dspy, fastapi, pydantic.
DSPy provides robust LLM prompt optimization for accurate text-to-HS code classification from raw cargo descriptions.
Capable LLM for classifying varied cargo descriptions into standardized HS codes.
## Deliverables
Submit runnable source, pinned dependencies, setup commands, a working interface, example outputs, and a recorded end-to-end demo. Include tests and an action log.
## Acceptance
- Correctly parses and validates mock FormSG webhook payload structures.
- Predicts valid 6-digit HS codes for diverse cargo descriptions using the LLM.
- Accurately calculates handling fees using the specified weight-based formula.
- Outputs a structured billing summary JSON for each authenticated payload.
## Starter Examples
```json
[
{
"input": {
"submission_id": "sub_123",
"signature_valid": true,
"form_responses": {
"cargo_description": "Frozen Atlantic Salmon fillets, packaged in dry ice",
"weight_kg": 500,
"hazardous": false
}
},
"expected_output": {
"submission_id": "sub_123",
"authentication_status": "VERIFIED",
"predicted_hs_code": "0304.41",
"cargo_category": "FROZEN_SEAFOOD",
"handling_fee_sgd": 250,
"billing_status": "DRAFT_READY"
}
},
{
"input": {
"submission_id": "sub_124",
"signature_valid": true,
"form_responses": {
"cargo_description": "Lithium-ion batteries for electric vehicles, UN3480",
"weight_kg": 1200,
"hazardous": true
}
},
"expected_output": {
"submission_id": "sub_124",
"authentication_status": "VERIFIED",
"predicted_hs_code": "8507.60",
"cargo_category": "DANGEROUS_GOODS",
"handling_fee_sgd": 840,
"billing_status": "DRAFT_READY"
}
}
]
```
## Safety
Maintains offline processing of mock webhook payloads without connecting to live customs or government endpoints.
Use mock external writes. Require human review before any real deployment.