信用证LC条款核对引擎·专业版
能力
确定性核对器:输入最迟装运日、有效期、交单期天数、证内条款全文、信用证类型、LC金额、合同金额与容差,自动输出总体风险等级(高/中/低)、四类核对明细、软条款命中清单与改证建议。
引擎源码(可直接运行)
# -*- coding: utf-8 -*-
"""信用证(LC)条款核对引擎 lc_checker.py
确定性核对规则:
1. 时间链:有效期 vs 最迟装运日(UCP600 交单默认 21 天)
gap < 0 倒挂 / 0-7 天 / 8-14 天 / 15-20 天 / >=21 天
2. 软条款:关键词命中(客检/船样/申请人指示/进口许可证/指定船只/会签)
3. 信用证类型:可撤销 revocable 高风险
4. 金额:LC 金额 vs 合同金额,超出容差高风险
任何一项高风险 => 总体高风险。
"""
from datetime import date, datetime
# (风险名, 关键词列表,中英文)
SOFT_CLAUSE_KEYWORDS = [
("检验证书由申请人/买方授权代表签发",
["申请人授权", "申请人指派的检验", "申请人签署的检验", "买方授权代表",
"authorized representative of the applicant", "applicant's authorized",
"inspection certificate signed by the applicant", "inspection issued by applicant"]),
("装运/船样须经申请人确认",
["船样经买方确认", "船样经申请人确认", "样品须经申请人确认", "样品须经买方确认",
"subject to applicant's confirmation", "subject to buyer's confirmation",
"shipping sample subject to"]),
("以申请人指示/通知为付款前提",
["凭申请人指示付款", "收到申请人通知后付款", "upon applicant's instruction",
"subject to applicant's instruction", "against applicant's instruction"]),
("以取得进口许可证为生效/付款前提",
["进口许可证签发后生效", "以取得进口许可证", "取得进口许可证为",
"upon receipt of import license",
"effective upon issuance of import license", "subject to import license"]),
("船只/船公司由申请人指定",
["由申请人指定船只", "船公司须经申请人同意", "指定船只由买方",
"vessel to be nominated by applicant", "vessel nominated by the applicant",
"shipping company subject to applicant"]),
("单据须申请人会签/回签",
["单据须经申请人会签", "申请人回签", "countersigned by the applicant",
"countersignature of the applicant"]),
]
def _to_date(v):
if isinstance(v, date):
return v
if isinstance(v, datetime):
return v.date()
if isinstance(v, str):
for fmt in ("%Y-%m-%d", "%Y/%m/%d", "%Y.%m.%d"):
try:
return datetime.strptime(v.strip(), fmt).date()
except ValueError:
continue
raise ValueError(f"日期格式无法解析: {v!r}(支持 YYYY-MM-DD / YYYY/MM/DD / YYYY.MM.DD)")
def detect_soft_clauses(clause_text):
"""返回命中软条款列表,每项 {risk, matched}。"""
if not isinstance(clause_text, str) or not clause_text.strip():
return []
hits = []
low = clause_text.lower()
for name, kws in SOFT_CLAUSE_KEYWORDS:
for kw in kws:
if kw.lower() in low:
hits.append({"risk": name, "matched": kw})
break
return hits
def check_time_chain(latest_shipment, expiry, presentation_days=21):
"""交单时间链核对。gap=有效期-最迟装运日(天)。"""
s = _to_date(latest_shipment)
e = _to_date(expiry)
if not isinstance(presentation_days, int) or presentation_days <= 0:
raise ValueError("交单期天数必须为正整数")
gap = (e - s).days
if gap < 0:
level, msg = "高", f"有效期早于最迟装运日{abs(gap)}天,时间链倒挂,无法按期交单"
elif gap <= 7:
level, msg = "高", f"有效期距最迟装运日仅{gap}天(≤7天),交单窗口过短,极易逾期"
elif gap < 15:
level, msg = "中", f"有效期距最迟装运日{gap}天(8-14天),交单时间紧张,需加急制单"
elif gap < presentation_days:
level, msg = "中", f"交单窗口{gap}天,短于惯例默认{presentation_days}天(UCP600)"
else:
level, msg = "低", f"有效期距最迟装运日{gap}天(≥{presentation_days}天),交单时间充裕"
return {"gap_days": gap, "level": level, "message": msg}
def check_lc_type(lc_type, clause_text=""):
"""信用证类型核对。UCP600 下不可撤销为默认;可撤销高风险。"""
t = (lc_type or "").strip().lower()
text = (clause_text or "").lower()
if t in ("revocable", "可撤销") or ("revocable" in t and "irrevocable" not in t):
return {"level": "高", "message": "信用证为可撤销(revocable),开证行可单方面改/撤,受益人无保障"}
if "this credit is revocable" in text and "irrevocable" not in text:
return {"level": "高", "message": "条款文本含 revocable 且未见 irrevocable,可撤销风险"}
if t in ("irrevocable", "不可撤销", ""):
return {"level": "低", "message": "未发现可撤销条款(UCP600 项下默认不可撤销)"}
return {"level": "中", "message": f"信用证类型未能明确判定({lc_type}),请核实是否标注 irrevocable"}
def check_amount(lc_amount, contract_amount=None, tolerance=0.0):
"""金额核对。无合同金额时仅校验 LC 金额为正数。"""
if lc_amount is None:
raise ValueError("LC 金额不能为空")
lc_amount = float(lc_amount)
if lc_amount <= 0:
raise ValueError("LC 金额必须为正数")
if contract_amount is None:
return {"level": "低", "message": "未提供合同金额,仅校验 LC 金额格式通过", "deviation_pct": None}
contract_amount = float(contract_amount)
if contract_amount <= 0:
raise ValueError("合同金额必须为正数")
if tolerance < 0 or tolerance > 1:
raise ValueError("容差必须在 0~1 之间(如 0.05 表示 5%)")
if contract_amount == 0:
raise ValueError("合同金额不能为 0")
dev = abs(lc_amount - contract_amount) / contract_amount
if dev <= tolerance:
return {"level": "低", "message": f"LC 金额与合同金额偏差 {dev*100:.2f}%,在容差 {tolerance*100:.0f}% 内", "deviation_pct": round(dev * 100, 2)}
return {"level": "高", "message": f"LC 金额与合同金额偏差 {dev*100:.2f}%,超出容差 {tolerance*100:.0f}%,存在不符点风险", "deviation_pct": round(dev * 100, 2)}
def check_lc(latest_shipment, expiry, clause_text="", presentation_days=21,
lc_type="", lc_amount=None, contract_amount=None, tolerance=0.0):
"""完整核对,返回结构化结论。"""
if not isinstance(clause_text, str):
raise ValueError("clause_text 必须为字符串")
soft = detect_soft_clauses(clause_text)
time_chain = check_time_chain(latest_shipment, expiry, presentation_days)
type_ck = check_lc_type(lc_type, clause_text)
amount_ck = check_amount(lc_amount, contract_amount, tolerance) if lc_amount is not None else {"level": "中", "message": "未提供 LC 金额,无法核对", "deviation_pct": None}
items = [time_chain, type_ck, amount_ck]
soft_level = "高" if soft else "低"
levels = [it["level"] for it in items] + [soft_level]
overall = "高" if "高" in levels else ("中" if "中" in levels else "低")
suggestions = []
if soft:
suggestions.append(f"发现 {len(soft)} 条软条款,要求改证删除或改为由第三方中立机构(如SGS)出具单据")
if time_chain["level"] != "低":
suggestions.append("要求延展信用证有效期/最迟装运日,保证交单期≥21天")
if type_ck["level"] == "高":
suggestions.append("拒绝可撤销信用证,要求改开不可撤销跟单信用证")
if amount_ck["level"] == "高":
suggestions.append("核对合同与信用证金额、币种与溢短装条款,必要时改证")
if not suggestions:
suggestions.append("未发现高风险条款,按证制单并保留全套交单凭证")
return {
"overall_risk": overall,
"soft_clauses": soft,
"soft_clause_count": len(soft),
"time_chain": time_chain,
"lc_type_check": type_ck,
"amount_check": amount_ck,
"suggestions": suggestions,
}
调用示例
from lc_checker import check_lc
from datetime import date
r = check_lc(
latest_shipment=date(2026, 11, 10),
expiry=date(2026, 11, 20),
clause_text="Inspection certificate signed by the applicant must be presented.",
lc_type="irrevocable",
lc_amount=50000, contract_amount=50000,
)
print(r["overall_risk"]) # 高
print(r["soft_clauses"][0]) # 客检软条款命中
print(r["suggestions"]) # 改证建议
判定规则
- 时间链:gap<0 倒挂或≤7天为高,8-14天为中,15-20天短于交单期为中,≥交单期(默认21天)为低;
- 软条款:六类关键词(中英文)命中即高风险,返回风险名与命中词;
- 类型:revocable/文本含 revocable 且无 irrevocable 为高风险;
- 金额:偏差>容差(如5%)为高风险;
- 总体:任一高风险项即为高风险,无高风险但有中风险为中,否则为低。
边界处理(已覆盖)
- 日期支持 YYYY-MM-DD / YYYY/MM/DD / YYYY.MM.DD;
- 金额容差临界 5.00% 放行、5.01% 拦截;
- 非法日期、交单期非正整数、金额≤0、容差超出0-1、条款文本非字符串:抛 ValueError 拦截。
断言测试结果(31 项全过)
- 4 个完整正例(低风险全绿、客检+时间紧张、可撤销+倒挂+金额超差、中文双软条款);
- 时间链 21/15/14/7/0/-1 临界逐档;
- 金额容差 5% 临界两组;
- 6 类非法入参全部拦截。
批量接入建议
- 到证后用 OCR/文本提取证内条款,循环调用本引擎逐条预审;
- 高风险证自动生成改证邮件草稿,交单证主管复核后发出;
- 核对结果与改证记录归档,形成单证风控台账。