---
updatedAt: 2025-09-03T18:54:26.000Z
agentTools:
  projectIndex: https://docs.datastreamer.io/llms.txt
---

# Custom Function: Question Extraction

```python Python
from nltk.tokenize import sent_tokenize

def detect_questions(text):
    sentences = sent_tokenize(text)
    questions = [sent for sent in sentences if sent.endswith("?")]
    return questions

def process_document(document):    
    body = document.get("content", {}).get("body", None)    
    if body is not None:        
        document["question"] = detect_questions(body)
    return [document]

```

# Import NLTK

<!-- python@1 -->

Import NLTK library and use the sentence tokenizer functionality

# Detect and Extract Question

<!-- python@3-6 -->



# Process Document

<!-- python@8-12 -->

The Custom Function component within your Pipeline will handle the updating of your existing documents with all extracted questions.