LLM-Driven Contract Testing for SWIFT Microservices
SwiftGuard is a lightweight, dependency-minimal contract testing framework designed to validate microservices that handle SWIFT (Society for Worldwide Interbank Financial Telecommunication) messages. In traditional financial software testing, generating high-quality, diverse, and edge-case-rich test data is a manual and error-prone process. SwiftGuard automates this using Generative AI.
Why is this important?
- Financial Compliance: SWIFT messages (like MT103) have strict formats and validation rules. Errors can lead to failed transactions and regulatory fines.
- Edge Case Discovery: Human testers often test "happy paths." LLMs can generate thousands of subtle variations (malformed tags, boundary values, incorrect sequences) to robustly stress-test the parser.
- Zero-Dependency Architecture: The core service runs on native Node.js (no Express/Fastify overhead), making it easy to deploy in restricted financial environments.
SwiftGuard connects to Generative AI Providers (Google Gemini, DeepSeek, Groq, Puter) to dynamically generate test data. Instead of relying on static .json or .xml stovepipes, we use the LLM as an intelligent fuzzer.
- Prompt Engineering: We feed the AI a strict prompt defining the SWIFT MT103 structure (e.g., Mandatory tags
:20:,:32A:,:50K:). - Dynamic Generation:
- Valid Scenario: We ask the AI to "Generate a valid MT103 message with strict SWIFT tags."
- Invalid Scenario: We ask the AI to "Generate an INVALID message missing mandatory tag :23B:."
- Validation:
- The generated message is sent to our local microservice (
POST /swift). - The service parses the message and validates it against a strict JSON Schema.
- The Playwright test suite asserts that the service correctly accepts valid messages and rejects invalid ones.
- The generated message is sent to our local microservice (
This approach ensures that your microservice is battle-tested against non-deterministic, AI-generated inputs, simulating real-world messiness better than static mock data.
- Multi-LLM Support: Switch between Gemini, DeepSeek, Groq, and Puter.ai based on your needs or quota.
- AI-Powered Fuzzing: Generates endless unique SWIFT message variations using state-of-the-art models.
- Strict Schema Validation: Uses
Ajv(Another JSON Schema Validator) to enforce business rules. - HTML-Only Dashboard: A lightweight, glassmorphism-styled UI to visualize processed messages in real-time.
- End-to-End Testing: Integrated
Playwrighttests verify the entire flow (Generation -> API -> UI).
- Node.js v18+
- An API Key for your chosen LLM Provider (Google Gemini, DeepSeek, or Groq).
-
Clone the repository:
git clone https://github.com/your-repo/swiftguard.git cd swiftguard -
Install dependencies:
npm install
-
Configure Environment: Create a
.envfile in the root directory and add the key for your active provider:# Option 1: Google Gemini GEMINI_API_KEY=your_gemini_key # Option 2: DeepSeek AI DEEPSEEK_API_KEY=your_deepseek_key # Option 3: Groq AI GROQ_API_KEY=your_groq_key
-
Select LLM Provider: Open
llm/swiftGenerator.jsand uncomment the provider you wish to use:// const generator = require('./geminiGenerator'); // const generator = require('./puterGenerator'); // const generator = require('./deepseekGenerator'); const generator = require('./groqGenerator'); // Active
This will spin up the local service, generate data via Gemini, and verify the results.
npx playwright testStart the service manually:
node service/swiftService.jsOpen your browser to: http://localhost:1934
llm/: Logic for interacting with Gemini API.parser/: Custom regex-based parser for raw SWIFT messages.contracts/: JSON Schema definitions for validation.service/: Native Node.js HTTP server.tests/: Playwright E2E test suite.ui/: Frontend dashboard.
Built with ❤️ using Node.js, Playwright, and Google Gemini.
Contributors
Mukul Dev Mahato - QA Automation Engineer | LinkedIn

