FOUNDRY
C8 Platform
← Tasks

Entry Type 11 validator

completedcode_genP2

Description

Validate Entry Type 11 (informal entry) eligibility based on value thresholds, commodity restrictions, and country of origin rules.
Assignee
-
Claimed By
Cloud Lu → Claude Sonnet
Created
21d ago
Completed
1d ago

Quality

Overall
39%
Pass
FAIL
Graded By
-
Graded At
-

Cost

Input Tokens
-
Output Tokens
-
Est. USD
-

Result

{
  "cost": {
    "input_tokens": 43,
    "estimated_usd": 0.064059,
    "output_tokens": 4262
  },
  "model": "claude-sonnet-4-20250514",
  "status": "success",
  "transport": "anthropic_api",
  "latency_ms": 54841,
  "response_text": "I'll help you create a validator for Entry Type 11 (informal entry) eligibility. Here's a comprehensive implementation:\n\n```python\nfrom typing import Dict, List, Optional, Tuple\nfrom dataclasses import dataclass\nfrom enum import Enum\nimport re\n\nclass ValidationResult(Enum):\n    ELIGIBLE = \"eligible\"\n    INELIGIBLE = \"ineligible\"\n    CONDITIONAL = \"conditional\"\n\n@dataclass\nclass ValidationIssue:\n    code: str\n    message: str\n    severity: str  # 'error', 'warning', 'info'\n\n@dataclass\nclass EntryDetails:\n    value: float\n    currency: str\n    commodity_code: str  # HTS code\n    commodity_description: str\n    country_of_origin: str\n    quantity: float\n    unit_of_measure: str\n    importer_type: str  # 'individual', 'commercial'\n    entry_purpose: str  # 'personal_use', 'commercial', 'gift'\n    \nclass EntryType11Validator:\n    def __init__(self):\n        # Value thresholds (in USD)\n        self.VALUE_THRESHOLDS = {\n            'individual_personal': 800.00,\n            'individual_gift': 100.00,\n            'commercial_general': 2500.00,\n            'commercial_textiles': 250.00  # Lower threshold for textiles\n        }\n        \n        # Restricted commodity codes (HTS codes that require formal entry)\n        self.RESTRICTED_COMMODITIES = {\n            # Agricultural products requiring permits\n            '0201', '0202', '0203', '0204',  # Meat products\n            '0401', '0402', '0403', '0404',  # Dairy products\n            '0701', '0702', '0703', '0704',  # Fresh vegetables\n            '0801', '0802', '0803', '0804',  # Fresh fruits\n            \n            # Controlled substances and chemicals\n            '2939', '2941',  # Antibiotics and medicinal chemicals\n            '3004',  # Pharmaceutical products\n            \n            # Textiles subject to quotas\n            '5208', '5209', '5210', '5211',  # Cotton fabrics\n            '6109', '6110', '6203', '6204',  # Clothing articles\n            \n            # Electronics requiring special handling\n            '8517',  # Telecommunications equipment\n            '8525',  # Transmission apparatus\n            \n            # Alcohol and tobacco\n            '2203', '2204', '2205', '2206',  # Alcoholic beverages\n            '2401', '2402', '2403',  # Tobacco products\n        }\n        \n        # Countries requiring special documentation\n        self.RESTRICTED_COUNTRIES = {\n            'CN': 'china_restrictions',  # China - anti-dumping duties\n            'RU': 'sanctions',  # Russia - sanctions\n            'IR': 'sanctions',  # Iran - sanctions\n            'KP': 'sanctions',  # North Korea - sanctions\n            'CU': 'embargo',    # Cuba - embargo\n        }\n        \n        # Countries eligible for preferential treatment\n        self.PREFERENTIAL_COUNTRIES = {\n            'CA', 'MX',  # NAFTA/USMCA\n            'AU', 'BH', 'CL', 'CO', 'CR', 'DO', 'SV', 'GT', 'HN', 'IL', \n            'JO', 'KR', 'MA', 'NI', 'OM', 'PA', 'PE', 'SG'  # FTA partners\n        }\n\n    def validate_entry(self, entry: EntryDetails) -> Tuple[ValidationResult, List[ValidationIssue]]:\n        \"\"\"\n        Main validation method for Entry Type 11 eligibility\n        \"\"\"\n        issues = []\n        \n        # Validate value thresholds\n        value_valid, value_issues = self._validate_value_threshold(entry)\n        issues.extend(value_issues)\n        \n        # Validate commodity restrictions\n        commodity_valid, commodity_issues = self._validate_commodity_restrictions(entry)\n        issues.extend(commodity_issues)\n        \n        # Validate country of origin rules\n        country_valid, country_issues = self._validate_country_restrictions(entry)\n        issues.extend(country_issues)\n        \n        # Validate quantity restrictions\n        quantity_valid, quantity_issues = self._validate_quantity_restrictions(entry)\n        issues.extend(quantity_issues)\n        \n        # Determine overall result\n        error_count = sum(1 for issue in issues if issue.severity == 'error')\n        warning_count = sum(1 for issue in issues if issue.severity == 'warning')\n        \n        if error_count > 0:\n            return ValidationResult.INELIGIBLE, issues\n        elif warning_count > 0:\n            return ValidationResult.CONDITIONAL, issues\n        else:\n            return ValidationResult.ELIGIBLE, issues\n\n    def _validate_value_threshold(self, entry: EntryDetails) -> Tuple[bool, List[ValidationIssue]]:\n        \"\"\"Validate entry value against applicable thresholds\"\"\"\n        issues = []\n        \n        # Convert to USD if necessary\n        usd_value = self._convert_to_usd(entry.value, entry.currency)\n        \n        # Determine applicable threshold\n        if entry.importer_type == 'individual':\n            if entry.entry_purpose == 'gift':\n                threshold = self.VALUE_THRESHOLDS['individual_gift']\n                threshold_type = \"gift threshold\"\n            else:\n                threshold = self.VALUE_THRESHOLDS['individual_personal']\n                threshold_type = \"personal use threshold\"\n        else:  # commercial\n            # Check if textiles\n            if self._is_textile_commodity(entry.commodity_code):\n                threshold = self.VALUE_THRESHOLDS['commercial_textiles']\n                threshold_type = \"commercial textile threshold\"\n            else:\n                threshold = self.VALUE_THRESHOLDS['commercial_general']\n                threshold_type = \"commercial threshold\"\n        \n        if usd_value > threshold:\n            issues.append(ValidationIssue(\n                code=\"VALUE_EXCEEDS_THRESHOLD\",\n                message=f\"Entry value ${usd_value:.2f} exceeds {threshold_type} of ${threshold:.2f}. Formal entry required.\",\n                severity=\"error\"\n            ))\n            return False, issues\n        \n        # Warning for values close to threshold (within 10%)\n        if usd_value > threshold * 0.9:\n            issues.append(ValidationIssue(\n                code=\"VALUE_NEAR_THRESHOLD\",\n                message=f\"Entry value ${usd_value:.2f} is near {threshold_type} of ${threshold:.2f}. Consider formal entry.\",\n                severity=\"warning\"\n            ))\n        \n        return True, issues\n\n    def _validate_commodity_restrictions(self, entry: EntryDetails) -> Tuple[bool, List[ValidationIssue]]:\n        \"\"\"Validate commodity code restrictions\"\"\"\n        issues = []\n        \n        # Check if commodity code is restricted\n        hts_prefix = entry.commodity_code[:4]  # First 4 digits of HTS code\n        \n        if hts_prefix in self.RESTRICTED_COMMODITIES:\n            restriction_type = self._get_restriction_type(hts_prefix)\n            issues.append(ValidationIssue(\n                code=\"RESTRICTED_COMMODITY\",\n                message=f\"Commodity {entry.commodity_code} ({restriction_type}) requires formal entry and additional documentation.\",\n                severity=\"error\"\n            ))\n            return False, issues\n        \n        # Check for controlled substances\n        if self._is_controlled_substance(entry.commodity_code):\n            issues.append(ValidationIssue(\n                code=\"CONTROLLED_SUBSTANCE\",\n                message=f\"Commodity {entry.commodity_code} is a controlled substance requiring formal entry.\",\n                severity=\"error\"\n            ))\n            return False, issues\n        \n        # Special handling for certain commodities\n        if self._requires_special_handling(entry.commodity_code):\n            issues.append(ValidationIssue(\n                code=\"SPECIAL_HANDLING_REQUIRED\",\n                message=f\"Commodity {entry.commodity_code} may require additional documentation or permits.\",\n                severity=\"warning\"\n            ))\n        \n        return True, issues\n\n    def _validate_country_restrictions(self, entry: EntryDetails) -> Tuple[bool, List[ValidationIssue]]:\n        \"\"\"Validate country of origin restrictions\"\"\"\n        issues = []\n        \n        country_code = entry.country_of_origin.upper()\n        \n        # Check for sanctioned/embargoed countries\n        if country_code in self.RESTRICTED_COUNTRIES:\n            restriction_type = self.RESTRICTED_COUNTRIES[country_code]\n            if restriction_type == 'embargo':\n                issues.append(ValidationIssue(\n                    code=\"EMBARGOED_COUNTRY\",\n                    message=f\"Goods from {country_code} are subject to embargo. Entry prohibited.\",\n                    severity=\"error\"\n                ))\n                return False, issues\n            elif restriction_type == 'sanctions':\n                issues.append(ValidationIssue(\n                    code=\"SANCTIONED_COUNTRY\",\n                    message=f\"Goods from {country_code} are subject to sanctions. Additional documentation required.\",\n                    severity=\"error\"\n                ))\n                return False, issues\n            else:\n                issues.append(ValidationIssue(\n                    code=\"COUNTRY_RESTRICTIONS\",\n                    message=f\"Goods from {country_code} may be subject to additional duties or requirements.\",\n                    severity=\"warning\"\n                ))\n        \n        # Check for preferential treatment eligibility\n        if country_code in self.PREFERENTIAL_COUNTRIES:\n            issues.append(ValidationIssue(\n                code=\"PREFERENTIAL_TREATMENT_AVAILABLE\",\n                message=f\"Goods from {country_code} may be eligible for preferential duty treatment.\",\n                severity=\"info\"\n            ))\n        \n        return True, issues\n\n    def _validate_quantity_restrictions(self, entry: EntryDetails) -> Tuple[bool, List[ValidationIssue]]:\n        \"\"\"Validate quantity restrictions for specific commodities\"\"\"\n        issues = []\n        \n        # Textile quota restrictions\n        if self._is_textile_commodity(entry.commodity_code):\n            if entry.quantity > self._get_textile_quota_limit(entry.commodity_code):\n                issues.append(ValidationIssue(\n                    code=\"QUOTA_EXCEEDED\",\n                    message=f\"Quantity {entry.quantity} {entry.unit_of_measure} exceeds quota limits for textile commodity.\",\n                    severity=\"error\"\n                ))\n                return False, issues\n        \n        # Agricultural quantity limits\n        if self._is_agricultural_commodity(entry.commodity_code):\n            if entry.quantity > self._get_agricultural_limit(entry.commodity_code):\n                issues.append(ValidationIssue(\n                    code=\"AGRICULTURAL_LIMIT_EXCEEDED\",\n                    message=f\"Quantity exceeds limits for agricultural imports. Permits may be required.\",\n                    severity=\"error\"\n                ))\n                return False, issues\n        \n        return True, issues\n\n    def _convert_to_usd(self, value: float, currency: str) -> float:\n        \"\"\"Convert currency to USD (simplified - would use real exchange rates)\"\"\"\n        # This would typically connect to a currency conversion service\n        exchange_rates = {\n            'USD': 1.0,\n            'EUR': 1.08,\n            'GBP': 1.27,\n            'CAD': 0.74,\n            'JPY': 0.0067,\n            'CNY': 0.14\n        }\n        \n        rate = exchange_rates.get(currency.upper(), 1.0)\n        return value * rate\n\n    def _is_textile_commodity(self, commodity_code: str) -> bool:\n        \"\"\"Check if commodity is a textile product\"\"\"\n        textile_chapters = ['50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63']\n        return commodity_code[:2] in textile_chapters\n\n    def _is_agricultural_commodity(self, commodity_code: str) -> bool:\n        \"\"\"Check if commodity is agricultural\"\"\"\n        agricultural_chapters = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15']\n        return commodity_code[:2] in agricultural_chapters\n\n    def _is_controlled_substance(self, commodity_code: str) -> bool:\n        \"\"\"Check if commodity is a controlled substance\"\"\"\n        controlled_prefixes = ['2939', '2941', '3004']\n        return any(commodity_code.startswith(prefix) for prefix in controlled_prefixes)\n\n    def _requires_special_handling(self, commodity_code: str) -> bool:\n        \"\"\"Check if commodity requires special handling\"\"\"\n        special_handling_chapters = ['84', '85', '87', '88', '90']  # Machinery, electronics, vehicles, etc.\n        return commodity_code[:2] in special_handling_chapters\n\n    def _get_restriction_type(self, hts_prefix: str) -> str:\n        \"\"\"Get the type of restriction for a commodity\"\"\"\n        restriction_map = {\n            '0201': 'meat products requiring FSIS inspection',\n            '0401': 'dairy products requiring FDA approval',\n            '2939': 'controlled pharmaceutical substances',\n            '6109': 'textile quota restrictions',\n            '8517': 'telecommunications equipment requiring FCC approval'\n        }\n        return restriction_map.get(hts_prefix, 'restricted commodity')\n\n    def _get_textile_quota_limit(self, commodity_code: str) -> float:\n        \"\"\"Get quota limit for textile commodities (simplified)\"\"\"\n        # This would typically reference current quota databases\n        return 1000.0  # Example limit\n\n    def _get_agricultural_limit(self, commodity_code: str) -> float:\n        \"\"\"Get quantity limit for agricultural commodities\"\"\"\n        # Personal use limits for agricultural products\n        return 50.0  # Example limit in kg\n\n# Example usage and testing\ndef main():\n    validator = EntryType11Validator()\n    \n    # Test case 1: Valid personal import\n    entry1 = EntryDetails(\n        value=500.00,\n        currency='USD',\n        commodity_code='6109100010',  # T-shirts\n        commodity_description='Cotton T-shirts',\n        country_of_origin='VN',  # Vietnam\n        quantity=10,\n        unit_of_measure='pieces',\n        importer_type='individual',\n        entry_purpose='personal_use'\n    )\n    \n    result1, issues1 = validator.validate_entry(entry1)\n    print(f\"Test 1 - Result: {result1.value}\")\n    for issue in issues1:\n        print(f\"  {issue.severity.upper()}: {issue.message}\")\n    print()\n    \n    # Test case 2: Value exceeds threshold\n    entry2 = EntryDetails(\n        value=3000.00,\n        currency='USD',\n        commodity_code='8517120000',  # Cell phones\n        commodity_description='Mobile phones',\n        country_of_origin='CN',  # China\n        quantity=5,\n        unit_of_measure='pieces',\n        importer_type='commercial',\n        entry_purpose='commercial'\n    )\n    \n    result2, issues2 = validator.validate_entry(entry2)\n    print(f\"Test 2 - Result: {result2.value}\")\n    for issue in issues2:\n        print(f\"  {issue.severity.upper()}: {issue.message}\")\n    print()\n    \n    # Test case 3: Restricted commodity\n    entry3 = EntryDetails(\n        value=200.00,\n        currency='USD',\n        commodity_code='0201300020',  # Beef\n        commodity_description='Fresh beef',\n        country_of_origin='AR',  # Argentina\n        quantity=5,\n        unit_of_measure='kg',\n        importer_type='individual',\n        entry_purpose='personal_use'\n    )\n    \n    result3, issues3 = validator.validate_entry(entry3)\n    print(f\"Test 3 - Result: {result3.value}\")\n    for issue in issues3:\n        print(f\"  {issue.severity.upper()}: {issue.message}\")\n\nif __name__ == \"__main__\":\n    main()\n```\n\nThis Entry Type 11 validator provides comprehensive checking for:\n\n## Key Features:\n\n1. **Value Thresholds**: Different limits for personal, commercial, gift, and textile imports\n2. **Commodity Restrictions**: HTS code-based restrictions for controlled substances, agricultural products, textiles\n3. **Country of Origin Rules**: Sanctions, embargos, and preferential treatment\n4. **Quantity Limits**: Quota restrictions for textiles and agricultural products\n\n## Validation Categories:\n\n- **Value-based**: Checks against de minimis and informal entry thresholds\n- **Commodity-based**: Identifies restricted HTS codes requiring formal entry\n- **Country-based**: Applies sanctions, embargos, and trade agreement rules\n- **Quantity-based**: Enforces quota and permit requirements\n\nThe validator returns detailed results with specific error codes and actionable messages for customs compliance."
}

Audit Trail (2)

1d agotask_completedTerminal Lu
1d agotask_claimedTerminal Lu
Task ID: 288d6d18-0d82-4f53-a013-15aaf78acca4