{"id":18761644,"url":"https://github.com/reflex-dev/valid_python_validator","last_synced_at":"2025-04-13T03:31:47.846Z","repository":{"id":222537515,"uuid":"757570669","full_name":"reflex-dev/valid_python_validator","owner":"reflex-dev","description":"Valid Python Guardrails AI validator - Validates that there are no Python syntactic bugs in the generated code.","archived":false,"fork":false,"pushed_at":"2024-04-08T18:21:00.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-08T00:17:28.799Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reflex-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-14T19:03:11.000Z","updated_at":"2024-05-08T00:17:28.800Z","dependencies_parsed_at":null,"dependency_job_id":"a1b91403-4e53-485a-bcf0-624d07df6021","html_url":"https://github.com/reflex-dev/valid_python_validator","commit_stats":null,"previous_names":["reflex-dev/valid_python_validator"],"tags_count":0,"template":false,"template_full_name":"guardrails-ai/validator-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reflex-dev%2Fvalid_python_validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reflex-dev%2Fvalid_python_validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reflex-dev%2Fvalid_python_validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reflex-dev%2Fvalid_python_validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reflex-dev","download_url":"https://codeload.github.com/reflex-dev/valid_python_validator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223564667,"owners_count":17165988,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T18:17:09.176Z","updated_at":"2024-11-07T18:17:09.944Z","avatar_url":"https://github.com/reflex-dev.png","language":"Python","readme":"# Overview\n\n| Developed by | Reflex |\n| --- | --- |\n| Date of development | Feb 15, 2024 |\n| Validator type | Format |\n| Blog | - |\n| License | Apache 2 |\n| Input/Output | Output |\n\n# Description\n\nThis validator checks if a string is valid Python syntax by trying to parse the string into an abstract syntax tree. Note that this validator doesn’t check for things such as correct argument names, etc.\n\n## Requirements\n\n* Dependencies:\n\t- guardrails-ai\u003e=0.4.0\n\n# Installation\n\n```bash\nguardrails hub install hub://reflex/valid_python\n```\n\n# Usage Examples\n\n## Validating string output via Python\n\nIn this example, we apply the validator to a string output generated by an LLM.\n\n```python\n# Import Guard and Validator\nfrom guardrails.hub import ValidPython\nfrom guardrails import Guard\n\n# Setup Guard\nguard = Guard().use(ValidPython, on_fail=\"exception\")\n\n# Correct python\ncorrect_python = \"\"\"\nimport os\n\ndef foo():\n    print(f\"Current path is: {os.getcwd()}\")\n\nfoo()\n\"\"\"\n\nincorrect_python = \"\"\"\nimport os\n\ndef foo()\n    print f\"Current path is: {os.getcwd()}\"\n\nfoo()\n\"\"\"\n\nguard.validate(correct_python)  # Validator passes\ntry:\n    guard.validate(incorrect_python)  # Validator fails\nexcept Exception as e:\n    print(e)\n```\nOutput:\n```console\nValidation failed for field with errors: Syntax error: expected ':'\n```\n\n# API Reference\n\n**`__init__(self, on_fail=\"noop\")`**\n\u003cul\u003e\nInitializes a new instance of the ValidPython class.\n\n**Parameters**\n- **`on_fail`** *(str, Callable)*: The policy to enact when a validator fails.  If `str`, must be one of `reask`, `fix`, `filter`, `refrain`, `noop`, `exception` or `fix_reask`. Otherwise, must be a function that is called when the validator fails.\n\u003c/ul\u003e\n\u003cbr/\u003e\n\n**`validate(self, value, metadata) -\u003e ValidationResult`**\n\u003cul\u003e\nValidates the given `value` using the rules defined in this validator, relying on the `metadata` provided to customize the validation process. This method is automatically invoked by `guard.parse(...)`, ensuring the validation logic is applied to the input data.\n\nNote:\n\n1. This method should not be called directly by the user. Instead, invoke `guard.parse(...)` where this method will be called internally for each associated Validator.\n2. When invoking `guard.parse(...)`, ensure to pass the appropriate `metadata` dictionary that includes keys and values required by this validator. If `guard` is associated with multiple validators, combine all necessary metadata into a single dictionary.\n\n**Parameters**\n- **`value`** *(Any):* The input value to validate.\n- **`metadata`** *(dict):* A dictionary containing metadata required for validation. No additional metadata keys are needed for this validator.\n\u003c/ul\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freflex-dev%2Fvalid_python_validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freflex-dev%2Fvalid_python_validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freflex-dev%2Fvalid_python_validator/lists"}