-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed_rules.py
More file actions
163 lines (153 loc) · 6.06 KB
/
seed_rules.py
File metadata and controls
163 lines (153 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
"""
Seed script to insert sample UCP600 rules into the database
"""
import os
import sys
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
# Add the app directory to the path so we can import our models
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from app.models import Rule
# Use SQLite for local development
DATABASE_URL = "sqlite:///./icc_rules.db"
# Create engine and session
engine = create_engine(DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
sample_rules = [
{
"source": "UCP600",
"rule_id": "UCP600_14A",
"article": "14",
"title": "Standard for Examination of Documents",
"reference": "UCP 600 Article 14(a)",
"version": "2007",
"text": "A nominated bank acting on its nomination, a confirming bank, if any, and the issuing bank must examine a presentation to determine, on the basis of the documents alone, whether or not the documents appear on their face to comply with the terms and conditions of the credit.",
"condition": {
"document_type": "letter_of_credit",
"examination_criteria": "documents_alone",
"compliance_check": "face_value_compliance"
},
"expected_outcome": {
"action": "examine_documents",
"basis": "face_value_only",
"standard": "apparent_compliance",
"reject_if": "discrepancies_apparent_on_face"
},
"tags": ["document_examination", "compliance", "presentation"],
"severity": "critical",
"deterministic": True,
"requires_llm": False,
"rule_metadata": {
"category": "examination_standards",
"sub_category": "document_compliance",
"banking_practice": "standard"
}
},
{
"source": "UCP600",
"rule_id": "UCP600_16A",
"article": "16",
"title": "Complying Presentation",
"reference": "UCP 600 Article 16(a)",
"version": "2007",
"text": "When the issuing bank determines that a presentation is complying, it must honour.",
"condition": {
"document_type": "letter_of_credit",
"presentation_status": "complying",
"bank_role": "issuing_bank"
},
"expected_outcome": {
"action": "honour_payment",
"obligation": "must_honour",
"condition": "complying_presentation_determined"
},
"tags": ["complying_presentation", "honour", "payment_obligation"],
"severity": "critical",
"deterministic": True,
"requires_llm": False,
"rule_metadata": {
"category": "payment_obligations",
"sub_category": "complying_presentation",
"banking_practice": "mandatory"
}
},
{
"source": "UCP600",
"rule_id": "UCP600_16D",
"article": "16",
"title": "Notice of Refusal",
"reference": "UCP 600 Article 16(d)",
"version": "2007",
"text": "When the issuing bank determines that a presentation does not comply, it may refuse to honour. If the issuing bank determines that the presentation does not comply, it must give a single notice to that effect to the presenter.",
"condition": {
"document_type": "letter_of_credit",
"presentation_status": "non_complying",
"bank_role": "issuing_bank",
"discrepancies_found": True
},
"expected_outcome": {
"action": "may_refuse_honour",
"notice_requirement": "single_notice_to_presenter",
"notice_content": "specify_discrepancies",
"timeline": "within_maximum_examination_period"
},
"tags": ["non_complying_presentation", "refusal", "notice_requirements"],
"severity": "high",
"deterministic": False,
"requires_llm": True,
"rule_metadata": {
"category": "rejection_procedures",
"sub_category": "notice_requirements",
"banking_practice": "conditional"
}
},
{
"source": "UCP600",
"rule_id": "UCP600-17-appearance",
"article": "17",
"title": "Document Appearance",
"reference": "UCP 600 Article 17",
"version": "2007",
"text": "Documents must not be inconsistent on their face. Documents presented which appear on their face to be inconsistent with one another will be considered as not appearing on their face to comply with the terms and conditions of the credit.",
"condition": None, # LLM rules don't need structured conditions
"expected_outcome": {
"action": "check_consistency",
"standard": "face_value_appearance",
"reject_if": "inconsistent_on_face"
},
"tags": ["document_appearance", "consistency", "face_value"],
"severity": "medium",
"deterministic": False,
"requires_llm": True,
"rule_metadata": {
"category": "document_standards",
"sub_category": "appearance_consistency",
"banking_practice": "interpretive"
}
}
]
def seed_database():
"""Insert sample rules into the database"""
db = SessionLocal()
try:
print("🌱 Seeding database with sample UCP600 rules...")
for rule_data in sample_rules:
# Check if rule already exists
existing_rule = db.query(Rule).filter(Rule.rule_id == rule_data["rule_id"]).first()
if existing_rule:
print(f"⚠️ Rule {rule_data['rule_id']} already exists, skipping...")
continue
# Create new rule
rule = Rule(**rule_data)
db.add(rule)
print(f"✅ Added rule: {rule_data['rule_id']} - {rule_data['title']}")
db.commit()
print(f"🎉 Successfully seeded {len(sample_rules)} UCP600 rules!")
except Exception as e:
print(f"❌ Error seeding database: {e}")
db.rollback()
raise
finally:
db.close()
if __name__ == "__main__":
seed_database()