Inspiration
Interactions with law enforcement are high-stakes, high-stress environments. In these moments, adrenaline often leads to a "legal freeze"โcitizens forget their rights, consent to searches they shouldn't, or inadvertently self-incriminate. We wanted to build a "second set of ears" that stays calm when the user can't, bridging the gap between complex legal statutes and real-time human interaction.
What it does
lawAIer is a proactive AI assistant that provides instant legal "guardrails" during live encounters.
Live Coaching: Monitors audio and provides immediate alerts (e.g., "You have the right to remain silent").
Document Intelligence: Scans warrants or tickets to verify validity and calculate potential DMV points.
Jurisdictional Awareness: Automatically pulls in state-specific laws based on the user's location.
Accountability: Generates a timestamped PDF incident report once the session ends for legal counsel.
How we built it
The core of lawAIer is built on a high-concurrency architecture designed for speed:
The Brain: We used Gemini 2.0 Flash via Vertex AI for its multimodal reasoning and incredibly low latency.
The Connection: We implemented the Google GenAI SDK to establish a persistent WebSocket connection, allowing us to stream audio in 4-second chunks rather than waiting for traditional HTTP request/response cycles.
The Memory: We used ChromaDB and Vertex AI Embeddings to store and retrieve state-specific laws.
The Output: ReportLab (Python) was used to dynamically render structured PDF reports.
Challenges we ran into
The primary hurdle was Latency vs. Accuracy. In a legal encounter, a 10-second delay is a failure. We had to optimize our audio chunking such that processing time is less than 1 sec. Initial tests using standard REST APIs were too slow. Moving to a streaming WebSocket architecture was a steep learning curve but ultimately the only way to achieve the "real-time" feel. Additionally, filtering out "background noise" from the actual legal dialogue required fine-tuning our prompt engineering.
Accomplishments that we're proud of
Sub-Second Latency via WebSockets: Successfully moving away from standard HTTP requests to a persistent WebSocket stream. Achieving a "real-time" feel where coaching cards appear almost instantly as the officer speaks was our biggest technical win.
Multimodal Integration: We didn't just build a chatbot; we built a comprehensive legal tool. Proudly integrating Gemini 2.0 Flashโs native ability to analyze audio, scan physical documents (warrants/tickets), and process video footage all within a single application.
The DMV Points Calculator: Developing a functional bridge between "AI vision" and "hard data." Extracting messy violation codes from a photographed ticket and mapping them to a state-specific points_data.json provides immediate, tangible value to the user.
Full-Stack Deployment: Taking the project from a local prototype to a production-ready state on Google Cloud Run using a custom CI/CD pipeline that handles the complex handshake between the React frontend and the FastAPI backend.
What we learned
Vector Search vs. Keyword Matching: We learned that semantic search is non-negotiable for legal tech. Traditional keyword matching fails when users use natural language (e.g., "they're looking in my trunk" vs. "vehicle search"). Using text-embedding-004 ensured the model always had the right legal context.
The Power of "Single-Call" Processing: Initially, we thought we needed separate calls for transcription, translation, and analysis. We learned that Gemini 2.0 Flash is powerful enough to handle all three in a single pass, which drastically reduced our API costs and processing time.
WebSocket State Management: Managing a persistent session in a "stop-restart" loop with MediaRecorder taught us a lot about handling binary data and base64 encoding in the browser to ensure the AI receives header-complete, playable audio chunks.
Edge Case Handling: We realized that "System Prompt Injection" is a fine art. Balancing the situation context, the state-specific laws, and the multilingual instructions required rigorous prompt engineering to prevent the model from becoming "chatty" or hallucinating statutes.
What's next for lawAIer
Offline Mode: Exploring a "lite" version of the law database stored in IndexedDB so users can access basic rights guidance even if they lose cellular data during an encounter.
Built With
- allowing-users-to-review-the-last-20-encounters-offline.-data-sources:-custom-curated-json-datasets-for-state-specific-laws-(ny
- ca
- chosen-for-its-native-support-for-asynchronous-websockets-and-high-speed-data-handling.-styling:-tailwind-css-for-a-modern
- chromadb
- ensuring-consistency-between-local-development-and-cloud-production-environments.-apis-&-libraries-websockets:-for-full-duplex
- fastapi
- federal)-and-a-dmv-violation-points-database.-cloud-&-infrastructure-platform:-google-cloud-platform-(gcp).-deployment:-cloud-run
- fl
- for-automated-containerization-(docker)-and-deployment-pipelines.-containerization:-docker
- gcp
- gemini
- genai
- images)-with-sub-second-latency.-embeddings:-vertex-ai-text-embedding-004
- mobile-first-design.-ai-&-machine-learning-(the-"brain")-large-language-model:-gemini-2.0-flash-via-vertex-ai.-this-was-critical-for-multimodal-analysis-(audio
- providing-a-serverless
- react
- reportlab
- responsive-user-interface.-backend:-fastapi-(python)
- scalable-environment-for-both-the-frontend-and-backend.-ci/cd:-google-cloud-build
- sdk
- speech-to-text
- tx
- used-to-convert-legal-statutes-into-mathematical-vectors-for-semantic-search.-sdk:-google-genai-sdk
- used-to-manage-the-persistent-websocket-connection-between-the-client-and-the-model.-data-&-storage-vector-database:-chromadb-(in-memory).-this-allowed-for-"semantic-law-retrieval
- vertexai
- video
- websockets
Log in or sign up for Devpost to join the conversation.