A Python package for processing and amending Israeli laws using AI
Project description
Israeli Law Amender
Project Overview
The Israeli Law Amender is a Python-based tool that automates the complex process of amending Israeli legislation. It leverages the power of Large Language Models (LLMs) to interpret amendment instructions and apply them to existing law documents, which are structured in JSON format. This project aims to significantly reduce the manual effort required to keep legal documents up-to-date, ensuring accuracy and consistency.
The tool is designed with two primary modes of operation: a training mode for batch processing and evaluation of the AI's performance, and a product mode for on-demand, interactive amendment of individual laws.
Features
- AI-Powered Amendments: Uses Google's Gemini models to generate Python scripts that perform the amendments.
- Dual-Mode Operation:
- Training Mode: Processes large batches of amendments from CSV files, designed for model evaluation and fine-tuning.
- Product Mode: Interactive command-line interface for amending single laws with user-provided text.
- Comprehensive Validation:
- In training mode, it performs a fuzzy matching score (Layer 1) and a more sophisticated LLM-based validation (Layer 3) to check the accuracy of the amendments.
- In product mode, it generates detailed HTML diff reports to visualize changes and runs Layer 3 validation.
- Structured Output: All generated files, including amended laws, scripts, and validation reports, are organized into a clear directory structure for easy review.
- Packaged for Convenience: The tool is set up as a Python package, allowing for easy installation and command-line access.
Workflow
Training Mode
- Input: The training mode is initiated with a command (
amend_law training) and reads predefined CSV files from theData/directory. Each CSV contains a list of laws and the corresponding amendment texts. - Processing: For each law, the script iterates through its amendments.
- Generation: For each amendment, it generates a prompt for the Gemini LLM, which returns a Python script designed to apply the amendment.
- Execution: The generated script is executed, applying the changes to the law's JSON structure.
- Validation: The amended law is validated against a "gold standard" version. The results, including fuzzy scores and Layer 3 validation scores, are logged.
- Output: All artifacts, including the amended JSONs, generated scripts, and validation summaries, are saved to their respective directories.
Product Mode
- Input: The product mode is initiated with the
amend_law productcommand. It then interactively prompts the user for:- The location of the original law JSON files.
- A main directory for all outputs.
- An API key if not already set as an environment variable.
- The law to be amended (by ID or name) or a CSV file with a list of laws.
- The amendment text (pasted directly, from a
.txtfile, or from the CSV).
- Processing: Based on the user's input, the tool prepares the data for the amendment process.
- Generation & Execution: Similar to the training mode, it generates and executes a Python script for each amendment.
- Reporting: After each amendment is applied, it generates:
- An HTML diff report showing the exact changes between the previous and the newly amended version.
- A Layer 3 validation report (in JSON format) that provides an AI-based assessment of the amendment's accuracy.
- Output: The amended law, the diff report, and the validation report are saved in the user-specified output directory.
Directory Structure
The project is organized as follows:
.
├── Data/ # Contains CSV files with amendment data.
├── Generated_Scripts_Generalized/ # Stores AI-generated Python scripts from training.
├── JSON_Laws_v2/ # Location of the original, unamended law JSONs.
├── JSON_amd*/ # Directories for amended JSONs from training, grouped by amendment number.
├── Src/ # Source code for the project.
│ ├── validation/ # Validation scripts.
│ ├── __init__.py
│ ├── Generalized_amd_flow.py
│ ├── laws_amending_script.py
│ └── product_flow_helpers.py
├── laws_to_review/ # Materials for low-scoring amendments are collected here for manual review.
├── main.py # Main entry point for the application.
├── README.md # This file.
└── setup.py # Package setup and configuration.
Installation and Dependencies
To set up the project, it is recommended to use a virtual environment.
-
Clone the repository:
git clone https://github.com/Miki-Kisel/Final-Project-Laws.git cd Final-Project-Laws
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the package: The project is configured as a Python package. Installing it will also handle all required dependencies.
pip install .
Dependencies
The main dependencies are:
google-generativeaipandasthefuzz[speedup]
These are installed automatically when you run pip install ..
Usage
Before running the tool, make sure to set your Google API key as an environment variable:
export GOOGLE_API_KEY="YOUR_API_KEY"
After installation, you can use the command-line tool amend_law.
Training Mode
To run the training mode, simply execute:
amend_law training
The script will use the predefined paths in Src/laws_amending_script.py to find the input data and save the results.
Product Mode
To run the interactive product mode, execute:
amend_law product
The script will then guide you through the process of providing the necessary files and information.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file israeli_law_amender-1.0.0.tar.gz.
File metadata
- Download URL: israeli_law_amender-1.0.0.tar.gz
- Upload date:
- Size: 121.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd6ec2580e380cd82139daffe2a7cd2a1d87da9415631e581bff70903c120ec0
|
|
| MD5 |
2548102706688c09d6261aec21b1f449
|
|
| BLAKE2b-256 |
ee02bf9e7a1fa483da4a39351533415771ff3ea52fca8486216423f0f94695c8
|
File details
Details for the file israeli_law_amender-1.0.0-py3-none-any.whl.
File metadata
- Download URL: israeli_law_amender-1.0.0-py3-none-any.whl
- Upload date:
- Size: 144.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15a46bcba0794211b878f2aceaabb0a1f57b72fb4fde6f3d1aef5ed938c08bdf
|
|
| MD5 |
c2ed08ee2bea17070e28df69844b3106
|
|
| BLAKE2b-256 |
579818eaf963efb7d912ec2e813ea40c3ae93df833c421cdf236c415e04438f2
|