# validate_postal_code

Extrai e normaliza código postal internacional (qualquer país exceto Brasil).

## config

- type: extraction
- version: 1.0
- languages: en, es, fr, de, it, pt-PT, nl, pl, ja, zh, ko, ar, any
- endpoint: /v1/extract/postal-code
- mcp_tool: nalu_extract_postal_code
- mcp_description: Extrai código postal internacional (qualquer país exceto Brasil). Para CEPs brasileiros use nalu_extract_cep. Retorna extracted_value com o código normalizado (maiúsculas, espaços padronizados). Sem enriquecimento de endereço — apenas validação de formato. Se has_suggestion=true, envie suggestion_to_agent ao usuário.

## deterministic_rules

### stop_words
hello, hi, good morning, good afternoon, i don't know, don't remember, no idea, bom dia, boa tarde, olá, oi, não sei, não lembro

### reject_patterns
- ^[a-zA-Z\s]+$
- ^0+$

### accept_patterns
- ([A-Z]{1,2}\d{1,2}[A-Z]?\s?\d[A-Z]{2})
- (\d{5}(-\d{4})?)
- ([A-Z]\d[A-Z]\s?\d[A-Z]\d)
- (\d{4,6})
- ([A-Z0-9]{2,4}\s[A-Z0-9]{2,4})

### constraints
- min_length: 3

## prompt

You are a postal code extractor. Given the dialogue below, extract the postal code the user provided.

Rules:
1. Extract the postal code exactly as the user wrote it — do not invent or guess.
2. Normalize: uppercase letters, single space where the format requires a space.
3. Do not look up or validate the address — only extract and normalize the format.
4. If the user did not provide a postal code or was evasive, return extracted_value: null.
5. Brazil-specific CEPs (8 digits, e.g. 01001-000) should NOT be extracted here — return null.

Dialogue:
Agent: {{agent_input}}
User: {{user_input}}

Agent context: {{agent_context}}

Reply ONLY with valid JSON, no markdown, no explanation:
{
  "extracted_value": "normalized postal code or null",
  "certain": true/false,
  "reasoning": "short explanation"
}

## few_shot_examples

### example 1
- agent_input: What is your postal code?
- user_input: SW1A 2AA
- output: {"extracted_value": "SW1A 2AA", "certain": true, "reasoning": "UK postcode format"}

### example 2
- agent_input: Please provide your ZIP code.
- user_input: My zip is 90210-1234
- output: {"extracted_value": "90210-1234", "certain": true, "reasoning": "US ZIP+4 format"}

### example 3
- agent_input: ¿Cuál es tu código postal?
- user_input: es 28080
- output: {"extracted_value": "28080", "certain": true, "reasoning": "Spanish postal code"}

### example 4
- agent_input: What is your postal code?
- user_input: K1A 0B1
- output: {"extracted_value": "K1A 0B1", "certain": true, "reasoning": "Canadian postal code format A1A 0A1"}

### example 5
- agent_input: What is your postal code?
- user_input: I'm not sure
- output: {"extracted_value": null, "certain": false, "reasoning": "User did not provide a postal code"}

## post_processors
- normalize_postal_code

## suggestions

### when_null_greeting
{{greeting_response}} To continue, I need your postal code. Please provide it.

### when_null_evasive
I need your postal code to proceed. Please enter it (e.g. SW1A 2AA, 90210, K1A 0B1).

### when_uncertain
I found this postal code: {{extracted_value}}. Is that correct?

### when_certain
Got it — postal code {{extracted_value}}.

### when_invalid
That doesn't look like a valid postal code. Please check and try again.
