> ## Documentation Index
> Fetch the complete documentation index at: https://futureagi.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Is Code

> Checks if the text contains valid programming code

# is-code

This evaluation template checks whether a given text contains valid programming code. It can identify code snippets across multiple programming languages and distinguish code from natural language.

## Interface Usage

```python theme={null}
result = evaluator.evaluate(
    eval_templates="is_code", 
    inputs={
        "input": """  
                  def fibonacci(n):  
                      a, b = 0, 1  
                      for _ in range(n):  
                          print(a)  
                          a, b = b, a + b  
                  """
    },
    model_name="turing_flash"
)

print(result.eval_results[0].metrics[0].value)
print(result.eval_results[0].reason)
```

## Python SDK Usage

```python theme={null}
from futureagi import Evaluator

# Initialize the evaluator
evaluator = Evaluator(api_key="your_api_key")

# Evaluate whether text contains valid code
result = evaluator.evaluate(
    eval_templates="is_code", 
    inputs={
        "input": """  
                  def fibonacci(n):  
                      a, b = 0, 1  
                      for _ in range(n):  
                          print(a)  
                          a, b = b, a + b  
                  """
    },
    model_name="turing_flash"
)

# Access the result
contains_code = result.eval_results[0].metrics[0].value
reason = result.eval_results[0].reason

print(f"Contains code: {contains_code}")
print(f"Reason: {reason}")
```

## Example Output

```python theme={null}
True
The input is clearly Python code that defines a function called 'fibonacci'. It has proper Python syntax including function definition with 'def', parameter declaration, variable assignments, a for loop with range(), indentation to denote code blocks, and function logic. This is a valid implementation of a function to print Fibonacci numbers.
```

## Troubleshooting

If you encounter issues with this evaluation:

* Ensure the code is properly formatted with appropriate indentation and syntax for its language
* This evaluation can identify code across common programming languages like Python, JavaScript, Java, etc.
* Mixed content (code with extensive natural language explanations) might yield uncertain results
* Code snippets with syntax errors might still be identified as code, as the evaluation focuses on structural patterns

## Related Evaluations

* **is-json**: Specifically checks if the text is a valid JSON structure
* **regex**: Validates if a string matches a specified pattern, useful for validating specific code patterns
* **json-schema**: Evaluates if a JSON object conforms to a specified schema
