Skip to content

PythonCode

Base classes

Name Children Inherits
BaseCode
llmling_agent.common_types
Base class for syntax-validated code.

⋔ Inheritance diagram

graph TD
  94743653783360["common_types.PythonCode"]
  94743655246992["common_types.BaseCode"]
  94743632922272["main.BaseModel"]
  139793542615232["builtins.object"]
  94743655246992 --> 94743653783360
  94743632922272 --> 94743655246992
  139793542615232 --> 94743632922272

🛈 DocStrings

Bases: BaseCode

Python with syntax validation.

Source code in src/llmling_agent/common_types.py
142
143
144
145
146
147
148
149
150
151
152
153
154
class PythonCode(BaseCode):
    """Python with syntax validation."""

    @field_validator("code")
    @classmethod
    def validate_syntax(cls, code: str) -> str:
        try:
            ast.parse(code)
        except SyntaxError as e:
            msg = f"Invalid Python syntax: {e}"
            raise ValueError(msg) from e
        else:
            return code

Show source on GitHub