
법인을 설립하여 주식 투자를 하고 있을 경우,
개별 매매에 대한 복식부기 회계처리를 일일이 해야하는게 참 귀찮을 수 있다.
그래서 AI를 활용하여 법인세 신고를 굳이 셀프로 처리해보고자 하였다.
우선 법인세 신고를 위해 거래내역에 대한 회계처리를 해야한다.
증권사 홈페이지로 들어가서 작년 1년간의 거래내역서를 신청하면,
메일로 PDF 파일을 보내준다.

비밀번호로 사업자등록번호를 입력하고 문서를 열람하면
아래와 같이 편집 권한이 비활성화되어 있다.

이 상태에서는 전처리가 안되기 때문에
pdf를 인쇄해서 pdf로 다시 변환해준다.

이제 gemini API를 이용해서 PDF 파일을 우선 JSON 파일로 변환해줄 것이다.
gemini API를 사용하는 이유는 꽁짜로 유료 API를 사용할 수 있기 때문이다.
구글 클라우드 플랫폼(GCP)을 신규 가입하면 90일간 쓸 수 있는 40만원 가량의 크레딧을 준다.
가입 방법은 link를 참고하시라
크레딧이 있으면, 제미나이 API 호출 시 발생하는 비용이 크레딧에서 먼저 차감된다.
API키를 발급받아 이 크레딧으로 Gemini API(Vertex AI)를 호출하여 PDF 파일을 json으로 바꿔주자
API키 발급 방법은 link를 참고하시라
거래명세서는 대충 이런 형식이다.

이걸 토대로 API에 던져줄 프롬프트는 아래와 같이 쌈마이하게 만들어봤는데 일단 동작은 잘한다.
더 효율적으로 동작하게 할 방법이 있을수도 있을 것 같은데 지금 알빠는 아닌 것 같다.
[Extraction Rules]
You are a financial data extraction expert. I will provide you with a chunk of a PDF document containing transaction histories.
Your goal is to extract ALL transaction records found in this chunk and return them in JSON format.
Extraction Logic:
- A single transaction record consists of a pair of two consecutive rows.
- First row generally contains: 거래일자, 종목명, 수량, 거래금액, 수수료, 변제/연체합, 예수금
- Second row generally contains: 통화, 거래구분, 단가, 거래금액(외), 거래세및농특세, 소득/주민세, 예수금(외)
- Combine these 2 rows into a single JSON object.
- If this chunk contains the first page of the document, completely ignore the cover/summary pages and start extracting ONLY after the string "■거래내역" appears.
- If this chunk does not contain "■거래내역", assume the document is a continuation of the table and extract all 2-row pairs that match the transaction data pattern.
Exclude Repeating Elements (Negative Prompting):
Absolutely ignore the following repeating header/footer text and do not treat them as data:
- "잔고 및 거래 명세서"
- "■거래내역" and "※ 수량단위 : ..."
- Table column names (e.g., 거래일자, 종목명, 통화, 거래구분 etc.)
- Top right "키움증권"
- "계좌번호 : ****-**** (주)****"
- "2025/01/01~2025/12/31 전체거래"
- Page numbers like "page : n/40"
- Timestamps like "2026-**-** **:**:**"
- Bottom left "원본"
- "-끝-", "키움증권 주식회사", and any stamp/seal.
Data Integrity:
- Extract the exact text. Do not remove commas (,) or symbols.
- If a specific field is ...

