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 integrates with Google Gemini (via @google/genai) 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 Gemini a strict prompt defining the SWIFT MT103 structure (e.g., Mandatory tags
:20:,:32A:,:50K:). - Dynamic Generation:
- Valid Scenario: We ask Gemini to "Generate a valid MT103 message with strict SWIFT tags."
- Invalid Scenario: We ask Gemini 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.
- AI-Powered Fuzzing: Uses
gemini-2.5-flashto generate endless unique SWIFT message variations. - 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+
- A Google Cloud Project with Gemini API enabled.
- An API Key.
-
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:GEMINI_API_KEY=your_actual_api_key_here
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

