---
updatedAt: 2025-05-06T14:14:56.000Z
agentTools:
  projectIndex: https://docs.datastreamer.io/llms.txt
---

# Custom Function: Passive Voice Detection

```python Python
from nltk import pos_tag
from nltk.tokenize import word_tokenize

def detect_passive_voice(text):
    words = word_tokenize(text)
    tags = pos_tag(words)
    for i in range(len(tags) - 2):
        if tags[i][1] == 'VBN' and tags[i+1][1] in ['IN', 'DT', 'TO']:
            return True   
    return False
  
def process_document(document):    
    body = document.get("content", {}).get("body", None)    
    if body is not None:        
        document["passive"] = detect_passive_voice(body)
    return [document]

```

```json Response Example
{"passive":true}
```

# Import NLTK

<!-- python@1,2 -->

This library allows for part of speech tagging and word tokenization

# Detect Passive Voice

<!-- python@4-10 -->



# Process Document

<!-- python@12-16 -->

The Custom Function component within your Pipeline will update existing documents true or false value depending if passive statements are found.