Files
group_xinghuo_jinrong/app/service/schema_meta.py
T
zyi b19a2415f9 feat: 数据分析 Agent 实现(API/服务/表结构元数据/文档/测试)
- 新增 app/api、app/service 数据分析 Agent 全套服务与接口
- schemas.py 重构为 schemas 包(analyst schema)
- 新增 SQL 防注入、guardrail、缓存、字典、LLM 等服务
- 新增 tests 测试套件与 scripts/dev、scripts/setup 脚本
- 补充需求规格、架构说明书、开发清单、表设计等文档
2026-09-09 18:04:45 +08:00

29 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""NL2SQL 的 schema 元数据注入(表/列说明,供 LLM 生成只读 SQL 时使用)。"""
SCHEMA_PROMPT = """可用数据表(全部只读,禁止任何写操作):
1. core_customer 客户主档:customer_id(客户编号), display_name(姓名), gender, age, occupation, annual_income(年收入), financial_asset(金融资产), is_hnw(高净值), service_tier, aml_risk_level, open_date, is_active
2. core_customer_risk 客户风险测评:customer_id, risk_code(C1~C5), max_loss_tolerance_pct, investment_goal, evaluated_at, is_authoritative
3. core_customer_advisor 客户-顾问归属:customer_id, advisor_id, rel_status(active/transferred/closed), effective_from
4. core_holding 持仓:customer_id, product_id, qty(份额), cost_amount(成本), market_value(市值), pnl_pct(盈亏百分比), as_of(截至日期)
5. core_trade 交易:trade_id, customer_id, product_id, trade_type('subscribe'=申购, 'redeem'=赎回), amount(金额), qty, channel, traded_at
6. core_cash_flow 资金流水:customer_id, flow_type('in'=入金, 'out'=出金), flow_subtype, amount, occurred_at
7. core_product 产品:product_id, product_name, product_type(公募基金/私募/理财/固收/信托/保险/贵金属), min_risk_code, term_days, fee_rate, is_open
8. core_product_nav 净值:product_id, nav(净值), daily_chg_pct, nav_date
9. core_staff 员工:staff_id, display_name, staff_type, roles
10. core_risk_grade 风险等级字典:code, grade_type, display_name, sort_order
11. jinrong_agent.risk_alert 预警台账:alert_id, customer_id, alert_type('large_amount'=大额/'freq_trade'=频繁/'suitability'=适当性/'aml'=反洗钱/'pattern'=模式), status('pending_review'=待处理/'confirmed_normal'/'confirmed_suspicious'/'reported'), risk_score, created_at
关系提示:
- 客户风险等级 = core_customer_risk.risk_code(C1~C5),关联 core_customer.customer_id。
- 客户持仓盈亏 = core_holding.pnl_pct;持仓市值 = core_holding.market_value。
- 产品类型/名称 = core_product(按 product_id 关联持仓/交易)。
- 顾问名下客户 = core_customer_advisor 中 rel_status='active' 的记录。
- 预警状态统计 = jinrong_agent.risk_alert.status。
- 时间用 traded_at / occurred_at / evaluated_at / nav_date / as_of。
MySQL 8 语法注意:
- 时间过滤请写 `traded_at >= CURDATE() - INTERVAL 30 DAY`(INTERVAL 后不带引号,单位用 DAY/MONTH)。
- 不要写 `INTERVAL '30 days'`(那是 ANSI 写法,MySQL 不认)。
"""