Intelligent Address Recognition: AI‑Assisted Hybrid Solution and Prompt Engineering
This article describes how a hybrid architecture that combines third‑party address‑recognition APIs with large‑language‑model (LLM) processing, along with carefully engineered prompts and a TSV output format, dramatically improves address parsing accuracy and latency in a retail checkout scenario.
What Is Intelligent Address Recognition
Intelligent address recognition parses unstructured text to automatically extract fields such as recipient name, phone number, province, city, county, and detailed address, converting them into structured data. For example:
"张三 13800138000 北京市海淀区中关村大街27号"
↓↓↓
{
userName: "张三",
tel: "13800138000",
province: "北京市",
city: "北京市",
county: "海淀区",
addressDetail: "中关村大街27号"
}Although address parsing is not a high‑frequency demand, its accuracy directly impacts payment experience and logistics fulfillment, giving it high business value.
Business Scenario
During holiday peaks, a specialty‑goods store sees a surge in orders that must be shipped via courier, requiring fast and accurate address extraction.
Problems Encountered
Initially we used a third‑party address‑recognition API offering province/city/county parsing, postal code detection, and latitude/longitude. However, we observed over 800 weekly failures caused by:
Diverse address formats (e.g., "浙江省/杭州市/余杭区..." vs. "杭州余杭五常街道...")
Non‑standard expressions (e.g., "杭城西湖区文三路")
API service interruptions (quota exhaustion or billing errors)
System defects included a lack of fallback mechanisms and complete reliance on manual intervention. Simple regex preprocessing helped little and even reduced the success rate of the third‑party API.
AI‑Driven Scenario
Recognizing that text understanding and structuring are AI strengths, we evaluated how LLMs could complement the API’s rigid limitations.
Core Pain Point
Traditional Limitation
AI Solution
Non‑standard address parsing
Low matching coverage
Semantic understanding (e.g., "杭城→杭州市")
Diverse format handling
Requires multiple parsing templates
Adaptive text‑structure parsing
Potential AI issues include the need for prompt‑tuning, possible slower response times, and uncontrolled output requiring continuous optimization.
Model Selection Considerations
Completeness of extracted fields (userName, tel, addressDetail, province, city, county, areaCode).
Response speed suitable for checkout scenarios.
Cost‑effectiveness for large‑scale usage.
Stability of the service; we chose the official API of the "千问‑plus" model.
Prompt Engineering
Initial prompt (JSON output):
给你一段地址内容,按如下格式提取出以下字段:
{
userName: 收件人名字,
tel: 手机号,
addressDetail: 含乡镇街道的详细地址,
province: 省/直辖市/港澳台,
city: 地级市,...
}
要求:1. 以JSON格式返回;2. 未提取到的字段为空字符串;3. 自动推导省市县;4. 根据地址推导areaCode。The JSON format incurred 3‑5 s latency, which was unacceptable. By switching to a TSV (Tab‑Separated Values) format, token usage dropped dramatically.
张三 13800138000 中关村大街27号 北京市 北京市 海淀区Revised prompt for TSV output:
将以下地址解析为TSV格式,仅返回一行数据,字段之间用制表符(\t)分隔,按照固定顺序输出:userName\ttel\taddressDetail\tprovince\tcity\tcounty。字段为空时返回空字符串,省/市/县若缺失需自动推导。This reduced average latency to 2‑3 s, comparable to the API call.
30‑Day Performance Data
Metric
Before Optimization
After Optimization
Overall Success Rate
87.60%
95.23%
AI fallback succeeded in 81.31 % of the cases where the third‑party API failed.
Post‑Optimization
We discovered that LLMs sometimes wrapped output in code blocks, breaking downstream parsers. Example:
```plaintext
张三 \t电话\t详细地址\t湖南省\t长沙市\t望城区
```To mitigate this, we:
Enhanced prompts to explicitly forbid code‑block markers.
Added tolerant parsing that strips surrounding ``` markers.
These steps further improved AI output stability.
Key Takeaways
Hybrid "API primary + LLM fallback" architecture yields >1 + 1 = 2 effect.
LLM can replace or augment traditional algorithms for complex text tasks.
Rapid prototyping and closed‑loop validation accelerate deployment.
Prompt engineering is akin to precision instrument calibration.
Choosing an efficient output format (TSV) can dramatically cut latency.
Conclusion
The story ends with the protagonist acknowledging that the hidden value of TSV is not just data but a higher level of cognitive insight.
Youzan Coder
Official Youzan tech channel, delivering technical insights and occasional daily updates from the Youzan tech team.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.