Skip to content

PythonCode

Base classes

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

⋔ Inheritance diagram

graph TD
  94461864870768["common_types.PythonCode"]
  94461860046656["common_types.BaseCode"]
  94461844082608["main.BaseModel"]
  139711135027392["builtins.object"]
  94461860046656 --> 94461864870768
  94461844082608 --> 94461860046656
  139711135027392 --> 94461844082608

🛈 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