search_legal_acts
Search Polish legal acts using filters like date, type, keywords, or title to find specific documents from official sources.
Instructions
Advanced search for Polish legal acts with multiple filters. Use this for finding specific documents by criteria like date, type, keywords, or title. Note: When using multiple keywords, ALL keywords must be present in the act (AND logic).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| year | No | Publication year (e.g., 2020, 2023) | |
| keywords | No | List of keywords to search in act content. ALL keywords must be present in the act (AND logic) | |
| date_from | No | Start date for effectiveness period (YYYY-MM-DD) | |
| date_to | No | End date for effectiveness period (YYYY-MM-DD) | |
| title | No | Text fragment to search in act titles | |
| act_type | No | Document type (e.g., 'Rozporządzenie', 'Ustawa') | |
| pub_date_from | No | Start date for publication period (YYYY-MM-DD) | |
| pub_date_to | No | End date for publication period (YYYY-MM-DD) | |
| in_force | No | Only return currently active acts. Type 'true' for active, 'false' for inactive | |
| limit | No | Maximum number of results (default: all matching) | |
| offset | No | Skip first N results for pagination |
Implementation Reference
- app.py:214-218 (registration)FastMCP decorator that registers the 'search_legal_acts' tool, defining its name, description, tags, and input schema via subsequent function parameters.@app.tool( name="search_legal_acts", description="Advanced search for Polish legal acts with multiple filters. Use this for finding specific documents by criteria like date, type, keywords, or title. Note: When using multiple keywords, ALL keywords must be present in the act (AND logic).", tags={"search", "acts", "filtering", "legal-research"} )
- app.py:219-325 (handler)The main handler function that executes the tool logic: constructs search parameters, queries the Sejm API endpoint https://api.sejm.gov.pl/eli/acts/search, processes the response, and returns the list of matching legal acts.def get_acts_list( year: Annotated[Union[int, str, None], "Publication year (e.g., 2020, 2023)"] = None, keywords: Annotated[list[str] | None, "List of keywords to search in act content. ALL keywords must be present in the act (AND logic)"] = None, date_from: Annotated[str | None, "Start date for effectiveness period (YYYY-MM-DD)"] = None, date_to: Annotated[str | None, "End date for effectiveness period (YYYY-MM-DD)"] = None, title: Annotated[str | None, "Text fragment to search in act titles"] = None, act_type: Annotated[str | None, "Document type (e.g., 'Rozporządzenie', 'Ustawa')"] = None, pub_date_from: Annotated[str | None, "Start date for publication period (YYYY-MM-DD)"] = None, pub_date_to: Annotated[str | None, "End date for publication period (YYYY-MM-DD)"] = None, in_force: Annotated[Union[bool, str], "Only return currently active acts. Type 'true' for active, 'false' for inactive"] = None, limit: Annotated[Union[int, str, None], "Maximum number of results (default: all matching)"] = None, offset: Annotated[Union[int, str, None], "Skip first N results for pagination"] = None ) -> list: """Fetches a list of legal acts from the Sejm API based on specified filters. This function provides comprehensive search capabilities for Polish legal acts, allowing filtering by multiple criteria including publication year, keywords, effective dates, document types, and current legal status. IMPORTANT: When providing multiple keywords, ALL keywords must be present in the act (AND logic). If no results are found, try using fewer or different keywords. IMPORTANT: If you want to find acts related to multiple categories/topics, search for them one keyword at a time. Args: year: Publication year (e.g., 2020, 2023). keywords: List of keywords to search in act content. ALL keywords must be present in the act (AND logic). date_from: Start date for effectiveness period (YYYY-MM-DD). date_to: End date for effectiveness period (YYYY-MM-DD). title: Text fragment to search in act titles. act_type: Document type (e.g., 'Rozporządzenie', 'Ustawa'). pub_date_from: Start date for publication period (YYYY-MM-DD). pub_date_to: End date for publication period (YYYY-MM-DD). in_force: Only return currently active acts ('true' for active, 'false' for inactive). limit: Maximum number of results to return. offset: Skip first N results for pagination. Returns: list: A list of legal acts matching the criteria, or empty list if no matches or error. Examples: User asks: "Please fetch all acts from the year 2020": Parameters: year = 2020 User asks: "Please fetch all regulations from 2020": Parameters: year = 2020, act_type = 'Rozporządzenie' User asks: "Please fetch all acts with keywords 'sąd' and 'prawnik'": IMPORTANT: This will find acts containing BOTH 'sąd' AND 'prawnik' Parameters: keywords = ['sąd', 'prawnik'] If you want to find acts containing 'sąd' OR 'prawnik', you need to search for them one keyword at a time. User asks: "Please fetch all acts with keywords 'sąd' or 'prawnik'": 1st run: Parameters: keywords = ['sąd'] 2nd run: Parameters: keywords = ['prawnik'] User asks: "Please fetch all currently active acts from 2020": Parameters: year = 2020, in_force = True User asks: "Please fetch acts containing 'zmieniające' in title from 2020": Parameters: year = 2020, title = 'zmieniające' User asks: "Please fetch first 10 acts from 2020": Parameters: year = 2020, limit = 10 """ logger.debug(f"get_acts_list called with filters: year={year}, keywords={keywords}, date_from={date_from}, date_to={date_to}, title={title}, act_type={act_type}, pub_date_from={pub_date_from}, pub_date_to={pub_date_to}, in_force={in_force}, limit={limit}, offset={offset}") try: # Build API request parameters from function arguments params = { "publisher": "DU", # Default to Dziennik Ustaw (primary legal gazette) } if year: params["year"] = int(year) if isinstance(year, str) else year if keywords: params["keyword"] = ",".join(keywords) if date_from: params["dateEffectFrom"] = date_from if date_to: params["dateEffectTo"] = date_to if title: params["title"] = title if act_type: params["type"] = act_type if pub_date_from: params["dateFrom"] = pub_date_from if pub_date_to: params["dateTo"] = pub_date_to if in_force is not None: params["inForce"] = bool(in_force) if limit: params["limit"] = int(limit) if isinstance(limit, str) else limit if offset: params["offset"] = int(offset) if isinstance(offset, str) else offset url = "https://api.sejm.gov.pl/eli/acts/search" # Make API request with constructed parameters response = requests.get(url, params=params, headers={"Accept": "application/json"}) response.raise_for_status() data = response.json().get("items", []) if not data: logger.info("get_acts_list returned no results") return [] logger.info(f"get_acts_list returned {len(data)} acts") return data except Exception as e: logger.error(f"Error: {e}") return []
- app.py:219-231 (schema)Input schema defined by Annotated type hints on function parameters, specifying optional filters for the search including year, keywords (AND logic), dates, title, type, publication dates, force status, limit, and offset.def get_acts_list( year: Annotated[Union[int, str, None], "Publication year (e.g., 2020, 2023)"] = None, keywords: Annotated[list[str] | None, "List of keywords to search in act content. ALL keywords must be present in the act (AND logic)"] = None, date_from: Annotated[str | None, "Start date for effectiveness period (YYYY-MM-DD)"] = None, date_to: Annotated[str | None, "End date for effectiveness period (YYYY-MM-DD)"] = None, title: Annotated[str | None, "Text fragment to search in act titles"] = None, act_type: Annotated[str | None, "Document type (e.g., 'Rozporządzenie', 'Ustawa')"] = None, pub_date_from: Annotated[str | None, "Start date for publication period (YYYY-MM-DD)"] = None, pub_date_to: Annotated[str | None, "End date for publication period (YYYY-MM-DD)"] = None, in_force: Annotated[Union[bool, str], "Only return currently active acts. Type 'true' for active, 'false' for inactive"] = None, limit: Annotated[Union[int, str, None], "Maximum number of results (default: all matching)"] = None, offset: Annotated[Union[int, str, None], "Skip first N results for pagination"] = None ) -> list: